小编smn*_*ino的帖子

Nunit:ParallelScope Self+Children、Fixture+Children 和 All 之间的区别

有人可以解释一下应用于基本 TestFixture 时所应用的 ParallelScope 的不同组合之间的区别(多个测试组件中的所有 TestFixture 均源自它):

[TestFixture, Parallelizable(ParallelScope.All)]

[TestFixture, Parallelizable(ParallelScope.Fixtures | ParallelScope.Children)]

[TestFixture, Parallelizable(ParallelScope.Self | ParallelScope.Children)]

Nunit文档也没有提供任何说明。另外,NUnit 文档中也没有提及ParallelScope.All

我想在所有测试程序集中并行运行所有测试用例。使用其中之一可以吗?有什么区别吗?使用其中一种比另一种有什么优势?

nunit nunit-3.0

6
推荐指数
1
解决办法
3884
查看次数

.Net核心中的二进制序列化

我正在研究.NET Core项目,我正在尝试解析我List<T>的问题byte[].使用.NET Framework,我们可以通过使用来实现相同的目标BinaryFormatter,但在撰写此问题时,看起来Microsoft似乎还没有在.NET Core中支持它,并且似乎没有即将发布的版本.

任何人都可以告诉如何在.NET Core中执行此序列化?此外,依赖于二进制序列化平台,因此在.NET Core中已弃用.

.net core binaryformatter

5
推荐指数
1
解决办法
3828
查看次数

Task.Run 不像 Thread.start 那样工作

我一直在开发一个应用程序,我需要以并行而不是阻塞的方式运行一些方法。首先我使用Task.Run,但在调试模式下,我看到操作阻塞并等待结果。我不想要这个,我想要在foreach 循环中调用的所有方法异步运行。

public async void f()
{
    foreach (var item in childrenANDparents)
    {
        await Task.Run(() => SendUpdatedSiteInfo(item.Host,site_fr));
        // foreach loop does not work until the task return and continues
    }
}
Run Code Online (Sandbox Code Playgroud)

所以我将 task.run 更改为 thread.start并且效果很好!

public async void f()
{
    foreach (var item in childrenANDparents)
    {
        Thread t = new Thread(() => SendUpdatedSiteInfo(item.Host, site_fr));
        t.Start();
        // foreach loop  works regardless of the method, in debug mode it shows me 
        // they are …
Run Code Online (Sandbox Code Playgroud)

c# multithreading task

5
推荐指数
2
解决办法
3886
查看次数

使用linq避免嵌套循环

我想创建一个方法来查找两个数之和的索引target.

所以,我创建了这个方法:

public static int[] TwoSum(int[] nums, int target)
{
    for (var i = 0; i < nums.Length; i++)
    {
        for (var j = 0; j < nums.Length; j++)
        {
            if (j == i) continue;

            if (nums[i] + nums[j] == target)
            {
                return new[] { i, j };
            }
        }
    }
}
Run Code Online (Sandbox Code Playgroud)

哪个工作正常.但是,我正在努力学习一些LINQ并且无法弄明白.我查看了各种示例,但我总是卡住,因为我使用了两次相同的数组.所以我不知道要选择什么以及如何访问它两次,同时确保它不会两次通过相同的索引.

任何从上述循环获得LINQ的帮助将不胜感激.

样本数据:

var nums = new [] { 2, 7, 11, 15 };
var target = 9;
Run Code Online (Sandbox Code Playgroud)

c# linq

5
推荐指数
0
解决办法
190
查看次数

InputSource和InputStream有什么区别?

解析xml时使用InputSource和InputStream有什么区别.我在一些教程中看到了这两个例子

没有InputSource:

InputStream is;
DocumentBuilderFactory dbFactory = DocumentBuilderFactory.newInstance();

DocumentBuilder db = dbFactory.newDocumentBuilder();
Document document = db.parse(is);
Run Code Online (Sandbox Code Playgroud)

和InputSource一样,差异在哪里

DocumentBuilder db = dbFactory.newDocumentBuilder();
InputSource inputSource = new InputSource(is);
Document document = db.parse(inputSource);
Run Code Online (Sandbox Code Playgroud)

那么性能有什么不同吗?还是别的什么?

java xml inputstream xml-parsing

4
推荐指数
1
解决办法
4997
查看次数

ASP.NET Core包含所有日志条目中的时间戳

我有一个ASP.NET Core 2.0应用程序,启用了内置控制台日志记录.这是WebHost的创建:

var webHost = WebHost.CreateDefaultBuilder(args)
            .UseUrls("http://localhost:5002")
            .UseStartup<Startup>()
            .UseApplicationInsights()
            .Build();

webHost.Run();
Run Code Online (Sandbox Code Playgroud)

发送HTTP POST请求时,将生成以下日志消息并显示在Console stdout中:

info: Microsoft.AspNetCore.Hosting.Internal.WebHost[1]
  Request starting HTTP/1.1 POST http://localhost:5002/api/sample application/json 2144
info: Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker[1]
  Executing action method MyApp.Controllers.SampleController.Post (Model.Solve) with arguments (MyApp.Request.MyRequest) - ModelState is Valid
info: Microsoft.AspNetCore.Mvc.Internal.ObjectResultExecutor[1]
  Executing ObjectResult, writing value Microsoft.AspNetCore.Mvc.ControllerContext.
info: Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker[2]
  Executed action MyApp.Controllers.SampleController.Post (MyApp) in 1201.9411ms
info: Microsoft.AspNetCore.Hosting.Internal.WebHost[2]
  Request finished in 1446.1907ms 200 application/json; charset=utf-8
Run Code Online (Sandbox Code Playgroud)

作为进入生产的一个要求,我需要所有日志条目都包含一个时间戳:现在,我知道我可以在调用Log()方法时自己提供时间戳,如GitHub ASP.NET Logging存储库中的这个开放性问题所述,但是我应该如何直接在WebHost生成的日志消息上这样做(如上所示)?有没有办法添加时间戳,而不必像在StackOverflow答案中提出的解决方案那样重写完整的自定义Logger ?

谢谢.

c# logging .net-core kestrel-http-server asp.net-core

4
推荐指数
2
解决办法
2457
查看次数

在Select上的C#Linq语法中创建新对象

我有一个Vector2对象列表.我想从每个元素中选择一个值并对这些值进行排序.在那之后,我想获得最低价值.

Vector2 cheapestCellPosition = openCells.Select(x => new {
        Vector2 = x,
        Value = GetCostToTarget(x, targetPosition) + GetCell(x).Cost.GetValueOrDefault()
    })
    .OrderBy(x => x.Value)
    .First();
Run Code Online (Sandbox Code Playgroud)

此代码抛出错误

CS0029 C#无法隐式转换匿名类型:Sym.Vector2 Vector2,int值为Sym.Vector2

我怎样才能解决这个问题?我需要根据当前元素设置Value属性.

c# linq

0
推荐指数
1
解决办法
155
查看次数