小编Kof*_*rfo的帖子

如何在SpecFlow功能中编写注释?

我想在SpecFlow功能中包含一些注释.

我收到以下错误:

Custom tool error: Parsing error near '/*'
Run Code Online (Sandbox Code Playgroud)

我尝试过以下方法:

// comment
/* comment */
-- comment
' comment
Run Code Online (Sandbox Code Playgroud)

我该怎么做呢?

specflow

46
推荐指数
2
解决办法
2万
查看次数

使用WEB API时,如何从POST中提取HttpResponseMessage中的内容?

一个非常典型的CRUD操作将导致一个对象的Id设置一旦持久化.

所以,如果我在接受一个对象的控制器上有Post方法(JSON序列化,比方说)并返回一个HttpResponseMessage,其中HttpStatusCode Created和Content设置为同一个对象,Id从null更新为整数,那么我如何使用HttpClient获取在那个Id值?

它可能很简单,但我看到的只是System.Net.Http.StreamContent.从post方法返回Int更好吗?

谢谢.

更新(以下回答):

一个工作的例子......

namespace TryWebAPI.Models {
    public class YouAreJoking {
        public int? Id { get; set; }
        public string ReallyRequiresFourPointFive { get; set; }
    }
}

namespace TryWebAPI.Controllers {
    public class RyeController : ApiController {
        public HttpResponseMessage Post([FromBody] YouAreJoking value) {
            //Patience simulated
            value.Id = 42;

            return new HttpResponseMessage(HttpStatusCode.Created) {
                Content = new ObjectContent<YouAreJoking>(value,
                            new JsonMediaTypeFormatter(),
                            new MediaTypeWithQualityHeaderValue("application/json"))
            };
        }
    }
}

namespace TryWebApiClient {
    internal class Program {
        private static void Main(string[] args) {
            var …
Run Code Online (Sandbox Code Playgroud)

asp.net-mvc serialization json.net asp.net-web-api

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

从WindowsIdentity和Thread.CurrentPrincipal检索WindowsPrincipal有什么区别?

我试图弄清楚为什么基于属性的安全性不能像我在WCF中所期望的那样工作,我怀疑它可能与以下内容有关:

AppDomain.CurrentDomain.SetPrincipalPolicy(PrincipalPolicy.WindowsPrincipal);

var identity = new WindowsIdentity("ksarfo");
var principal = new WindowsPrincipal(identity);
Console.WriteLine("\nChecking whether current user [" + identity.Name + "] is member of [" + groupName + "]");
Console.WriteLine(principal.IsInRole(groupName)); // returns true

principal = (WindowsPrincipal)Thread.CurrentPrincipal;
identity = (WindowsIdentity) principal.Identity;
Console.WriteLine("\nChecking whether current user [" + identity.Name + "] is member of [" + groupName + "]");
Console.WriteLine(principal.IsInRole(groupName)); // returns false
Run Code Online (Sandbox Code Playgroud)

我不明白为什么函数调用的结果不同:

principal.IsInRole(groupName)
Run Code Online (Sandbox Code Playgroud)

为了完整起见,代码实际失败的点在这里:

PrincipalPermission(SecurityAction.Demand, Role = "PortfolioManager")]
Run Code Online (Sandbox Code Playgroud)

帮助赞赏.

c# security active-directory windows-principal wcf-security

15
推荐指数
1
解决办法
1万
查看次数

为什么Windows\Assembly中可能缺少System.Threading.dll?

我在运行XP Professional的远程计算机上安装了各种版本的.NET Framework(版本1.1到4.0).我已经安装了Reactive Extension以获得良好的衡量标准.

我还有一个可以在我的机器上运行的应用程序,因为它引用了System.Threading在这里找到:C:\ Program Files\Microsoft Reactive Extensions\redist\desktopV2\System.Threading.dll

我在GAC中也有两个版本的DLL.

两个问题:

i)为什么当我从列表中选择而不是浏览到文件时,Visual Studio决定这是引用的版本(实例)?

ii)为什么远程机器上不存在System.Threading?(我认为这是框架的核心部分)

谢谢

.net multithreading system.reactive

7
推荐指数
1
解决办法
1万
查看次数

为什么非托管内存占控制台应用程序使用的内存的60%以上?

我正在使用ANTS Memory Profiler 7.0分析内存使用情况,并注意到控制台应用程序的非托管内存使用量大约为193MB(约62%),只比1000万左右的记录填充一些DTO.

非托管内存的帮助文本说:

内存分配给应用程序中未作为纯.NET代码运行的部分.这包括公共语言运行时本身,图形缓冲区以及通过P/Invoke或COM +访问的任何非托管数据

为什么这个数字会如此之高?

.net c# memory memory-management red-gate-ants

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

使用 ASP.NET Core 时,为什么 HttpContext.User.Identity.Name 对于等效于工作同步控制器的异步控制器显示为空?

TLDR;我有几乎相同的控制器,它们仅通过使用async/ await(当然还有Task)而存在实质性差异。非异步版本按预期返回当前用户的用户名,但async等效版本不会。

我想发现的是

  1. 这可能适用的情况
  2. 我可以使用这些工具(除了 Fiddler)来调查这个

注意:我无法针对 ASP.NET Core 源进行调试,因为尚未授予运行权限Set-ExecutionPolicy(这似乎是构建解决方案所必需的)

这有效:

using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;

namespace Baffled.API.Controllers
{
    [Authorize]
    [ApiController]
    [Route("[controller]")]
    public class IdentityController : ControllerBase
    {
        private readonly string userName;

        public IdentityController(IHttpContextAccessor httpContextAccessor)
        {
            userName = httpContextAccessor?.HttpContext?.User.Identity?.Name;
        }

        [HttpGet]
        public IActionResultGetCurrentUser()
        {
            return Ok(new { userName });
        }
    }
}
Run Code Online (Sandbox Code Playgroud)

这并不能正常工作:

using System.Threading.Tasks;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Logging;
using Baffled.Services;

namespace Baffled.API.Controllers
{ …
Run Code Online (Sandbox Code Playgroud)

c# windows-authentication asp.net-core asp.net-core-webapi ntlm-authentication

2
推荐指数
1
解决办法
72
查看次数

在C#中将List <string>转换为List <int>的最快方法是什么,假设int.Parse适用于每个项目?

最快我的意思是什么是使用C#将List中的每个项目转换为int类型的最高效方法,假设int.Parse适用于每个项目?

c# generics performance list

0
推荐指数
2
解决办法
629
查看次数

我如何从IQueryable <T>转换为IQueryable <U>和<Func <T,bool >>到<Func <U,bool >>以获得乐趣?

有人可以建议我如何编辑以下内容,以便我可以IQueryable<B>repoA给定的谓词返回Func<B, bool>

提前致谢.

interface IRepo<T> {
    IQueryable<T> FindBy(Func<T, bool> predicate);
} 

class A {
    public int Id { get; set; }
    public string Name { get; set; }
}

class RepoA : IRepo<A> {
    public IQueryable<A> FindBy(Func<A, bool> predicate) {
        return new EnumerableQuery<A>(new A[1]);
    }
}

class B {
    public int Id { get; set; }
    public string Name { get; set; }
}

class RepoB : IRepo<B> {
    IRepo<A> repoA = new RepoA(); …
Run Code Online (Sandbox Code Playgroud)

.net c# linq generics

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

用单个状态构造日期序列的优雅算法是什么?

给定任何一系列输入日期,其中单个状态为打开或关闭,以便至少有一个输入日期(打开状态),这将导致添加单个日期(已关闭,最大日期)以完成输出序列你会用什么算法来生成服从以下的输出?

1.没有连续的开放日期,也没有连续的关闭日期.

2.对于每个开放日期,只有一个截止日期.

3.第一个日期应为"开放",最后一个日期应为"关闭".

4.除了第一个开放日期和最后一个关闭日期之外,每个开放日期应紧跟上一个关闭日期,或换句话说,每个开放日期应该是下一个开放日期的前一天.

5.最终日期为已结束日期和最长日期(在此示例中为9999-12-31)

这不是一个家庭作业,我用C#实现了它,它的生产代码将执行数百万次.性能很重要,是的,但非常可读性.我使用的算法效果很好,但看起来很糟糕.任何语言欢迎.我会在必要时翻译.谢谢.

例1

input:
[2000-01-01,open] 

output: 
[2000-01-01,open]
[9999-12-31,closed]
Run Code Online (Sandbox Code Playgroud)

例2

input: 
[2000-01-01,open]
[2001-01-01,open]

output: 
[2000-01-01,open]
[2000-12-31,closed]
[2001-01-01,open]
[9999-12-31,closed]
Run Code Online (Sandbox Code Playgroud)

例3

input: 
[2000-01-01,open]
[2004-04-30,closed]

output: 
[2000-01-01,open]
[2004-04-30,closed]
[2004-05-01,open]
[9999-12-31,closed]
Run Code Online (Sandbox Code Playgroud)

例4

input: 
[2000-01-01,open]
[2000-03-17,open]
[2002-09-11,closed]
[2003-04-07,closed]

output: 
[2000-01-01,open]
[2000-03-16,closed]
[2000-03-17,open]
[2002-09-11,closed]
[2002-09-12,open]
[2003-04-07,closed]
[2003-04-08,open]
[9999-12-31,closed]
Run Code Online (Sandbox Code Playgroud)

我敢问哪种语言最能解决这类问题?

algorithm

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