小编Sam*_*ach的帖子

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

在WebApi 2中记录500个错误

如何记录Web Api 2中所有操作返回的所有内部服务器错误500错误?如何拦截错误以便能够记录堆栈跟踪?

logging interceptor asp.net-web-api asp.net-web-api2

6
推荐指数
2
解决办法
1970
查看次数

你能用C#代码在IIS中托管的asp.net core 2.0中设置请求超时吗?

有没有一种方法来设置requestTimeout从C#,而不是需要来设置requestTimeoutweb.config

asp.net托管在IIS中

<?xml version="1.0" encoding="utf-8"?>
<configuration>
  <system.webServer>
    <handlers>
      <add name="aspNetCore" path="*" verb="*" modules="AspNetCoreModule" resourceType="Unspecified" />
    </handlers>
    <aspNetCore requestTimeout="00:00:04" processPath="dotnet" arguments=".\Foo.dll" stdoutLogEnabled="false" stdoutLogFile=".\logs\stdout" />
  </system.webServer>
</configuration>
Run Code Online (Sandbox Code Playgroud)

不是这样的

iis .net-core asp.net-core asp.net-core-webapi asp.net-core-2.0

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

返回字符串时的编译器优化

如果我有

private string Foo(string decrypted)
{
    return decrypted.Substring(blah);
}
Run Code Online (Sandbox Code Playgroud)

private string Foo(string decrypted)
{
    string s = decrypted.Substring(blah);
    return s;
}
Run Code Online (Sandbox Code Playgroud)

这是一样的吗?编译器是否能够删除s

怎么样

private string Foo(string decrypted)
{
    string s = decrypted.Substring(blah);
    string t = s;
    return t;
}
Run Code Online (Sandbox Code Playgroud)

谢谢.

c# compiler-construction compiler-optimization

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

我应该为EF6实现Repository,Work of Work?

由于MSDN说的是关于DbContext:

DbContext实例表示工作单元和存储库模式的组合,以便它可以用于从数据库进行查询并将更改组合在一起,然后将更改作为一个单元写回到存储中.DbContext在概念上类似于ObjectContext.

使用EF5 +时,实现这两个(工作单元和存储库)是不是多余的?

有人可以对这个问题有所了解吗?

我打算使用SQL服务器构建一个基于MVC的应用程序,在阅读了大量关于具有单元可测试性的数据访问技术后,我对上述信息感到很遗憾!

c# asp.net-mvc unit-testing entity-framework

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

如何创建下载文本文件的SHA256哈希

我有一个项目,我获取文件的URL(例如www.documents.com/docName.txt),我想为该文件创建一个哈希.我怎样才能做到这一点.

FileStream filestream;
SHA256 mySHA256 = SHA256Managed.Create();

filestream = new FileStream(docUrl, FileMode.Open);

filestream.Position = 0;

byte[] hashValue = mySHA256.ComputeHash(filestream);

Label2.Text = BitConverter.ToString(hashValue).Replace("-", String.Empty);

filestream.Close();
Run Code Online (Sandbox Code Playgroud)

这是我必须创建哈希的代码.但是看看它如何使用文件流它使用存储在硬盘上的文件(例如c:/documents/docName.txt)但是我需要它来处理文件的URL而不是驱动器上文件的路径.

c# hash filestream

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

C#"不包含带'1'参数的构造函数"

我已经阅读了本网站上有关此错误的一些帖子,但我仍然无法弄清楚如何做到这一点 - 我对C#很新.

我试图从Form1到Form3传递多个文本框数据(只有2个开头)(Form2将是我工作后添加的中介)这个想法是创建几个表单,将数据传递到最后一个表单并使用标签,此刻Form3,然后Form3将一切保存到文件或数据库.希望有道理.

所以,我的代码中有几个代码段:

在Form1上我有:

    public Form1()
    {
        InitializeComponent();
    }

    private void nextBtn_Click(object sender, EventArgs e)
    {
        Form3 a = new Form3(firstNameTxtBox.Text);
        a.Show();

        Form3 b = new Form3(lastNametextBox.Text);
        b.Show();

        this.Hide();
    }
Run Code Online (Sandbox Code Playgroud)

在Form3上我有:

    public partial class Form3 : Form
    {
        public Form3(string a, string b)
        {
           InitializeComponent();
           firstNameLbl.Text = a;
           lastNameLbl.Text = b;
        }
    }
Run Code Online (Sandbox Code Playgroud)

现在,如果我拿出字符串b,它工作正常,那么我做错了什么呢?

c# visual-studio-2010

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

检测是否已手动输入HealthKit活动

您可以通过"来源"活动检查哪个应用插入了活动.有没有办法知道活动是否已手动输入,或者活动是否是从传感器实时录制并添加到HealthKit的活动?

iphone objective-c ios swift healthkit

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

模拟流以读取byte []

我的SUT需要一个Stream参数,做一些工作,然后返回一个byte[]:

public byte[] ProcessRequest(INetworkStream networkStream)
Run Code Online (Sandbox Code Playgroud)

INetworkStream包裹Stream.

我想模拟Stream参数来控制它读取的字节,所以我可以用这些字节测试方法.

stream.Read(buffer, offset, size);
Run Code Online (Sandbox Code Playgroud)

Stream.Read(...)返回int并填充buffer参数.

使用Moq如何伪造调用的结果INetworkStream.Read(...)(所以我控制byte[]返回值的长度和buffer参数)?

流包装:

public class FakeNetworkStream : INetworkStream
{
    private NetworkStream stream;

    public FakeNetworkStream(NetworkStream ns)
    {
        if (ns == null) throw new ArgumentNullException("ns");
        this.stream = ns;
    }

    public bool DataAvailable
    {
        get
        {
            return this.stream.DataAvailable;
        }
    }

    public int Read(byte[] buffer, int offset, int size)
    { …
Run Code Online (Sandbox Code Playgroud)

.net c# nunit moq mocking

3
推荐指数
1
解决办法
4493
查看次数

与具有相同名称和不同返回类型的成员的接口

为什么我不能做以下事情?

public interface ICommunication
{
    int Send(Dictionary<string, string> d);
    int Send(byte[] b);

    Dictionary<string, string> Receive();
    byte[] Receive(); // Error
}
Run Code Online (Sandbox Code Playgroud)

符号Receive()是不同的,但参数是相同的.为什么编译器会查看参数而不是成员签名?

ICommunication'已经定义了一个名为'Receive'的成员,它具有相同的参数类型.

我怎么能绕过这个?

我可以重命名Receive()如下,但我更喜欢保持命名Receive().

public interface ICommunication
{
    int Send(Dictionary<string, string> d);
    int Send(byte[] b);

    Dictionary<string, string> ReceiveDictionary();
    byte[] ReceiveBytes(); 
}
Run Code Online (Sandbox Code Playgroud)

.net c# interface method-signature

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