小编Mik*_*oud的帖子

依赖DLL未被复制到Visual Studio中的生成输出文件夹

我有一个visual studio解决方案.我在解决方案中有很多项目.有一个主要项目作为启动并使用其他项目.有一个项目说"ProjectX".它的参考被添加到主项目中.ProjectX引用了另一个不是解决方案的.NET dll(例如abc.dll).

现在这个abc.dll应该被复制到主项目的bin/debug文件夹中,但它不会被复制到那里.为什么不被复制,任何已知的原因?

.net c# dll reference visual-studio-2010

175
推荐指数
8
解决办法
14万
查看次数

为System.Net.HttpClient get构建查询字符串

如果我希望使用System.Net.HttpClient提交http get请求,似乎没有api添加参数,这是正确的吗?

是否有任何简单的api可用于构建查询字符串,该字符串不涉及构建名称值集合和url编码那些然后最终连接它们?我希望使用类似RestSharp的api(即AddParameter(..))

.net c# http

159
推荐指数
6
解决办法
14万
查看次数

如何结合|| 运营商在条件声明中

代替

if (foo == "1" || foo == "5" || foo == "9" ... ) 
Run Code Online (Sandbox Code Playgroud)

我喜欢将它们组合成以下(不起作用):

if (foo == ("1" || "5" || "9" ... ))
Run Code Online (Sandbox Code Playgroud)

那可能吗?

.net c#

77
推荐指数
8
解决办法
2456
查看次数

将货币字符串转换为小数?

目的

排序string是显示这样的货币数据$1,995.94数值在一组数据.

我目前正在使用下面的代码示例将string值转换为decimal我可以正确排序.

if (sortBy == "checkAmount")
{
    StringBuilder sb = new StringBuilder();
    foreach (var c in Convert.ToString(p.GetType().GetProperty(sortBy).GetValue(p, null)))
    {
        if (!char.IsDigit(c) && c != '.') { continue; }
        sb.Append(c);
    }
    return Convert.ToDecimal(sb.ToString());
}
else
{
    return p.GetType().GetProperty(sortBy).GetValue(p, null);
}
Run Code Online (Sandbox Code Playgroud)

问题

有什么更好的方法呢?它有效,而且很酷,但它不是很优雅.

最终解决方案

Servy提供的答案按预期工作,我使用了一段时间的实现,但是我和一位同事找到了更好的方法,所以我在这里记录它.顺便说一句,我最终最终使用了这个解决方案.

decimal.Parse(input, NumberStyles.AllowCurrencySymbol | NumberStyles.Number);
Run Code Online (Sandbox Code Playgroud)

.net c# type-conversion

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

导致"扩展方法无法动态调度"的原因在这里?

编译错误

'System.Data.SqlClient.SqlConnection'没有名为'Query'的适用方法,但似乎有一个名称的扩展方法.无法动态分派扩展方法.考虑转换动态参数或调用扩展方法而不使用扩展方法语法.

现在,我知道如何解决这个问题,但我正在努力更好地理解错误本身.我正在上课,以利用Dapper.最后,我将提供一些更多自定义功能,以使我们的数据访问类型更加简化.特别是在追踪和东西建设.但是,现在它就像这样简单:

public class Connection : IDisposable
{
    private SqlConnection _connection;

    public Connection()
    {
        var connectionString = Convert.ToString(ConfigurationManager.ConnectionStrings["ConnectionString"]);
        _connection = new SqlConnection(connectionString);
        _connection.Open();
    }

    public void Dispose()
    {
        _connection.Close();
        _connection.Dispose();
    }

    public IEnumerable<dynamic> Query(string sql, dynamic param = null, IDbTransaction transaction = null, bool buffered = true, int? commandTimeout = null, CommandType? commandType = null)
    {
        // this one works fine, without compile error, so I understand how to
        // workaround the error
        return Dapper.SqlMapper.Query(_connection, sql, param, transaction, buffered, …
Run Code Online (Sandbox Code Playgroud)

.net c# extension-methods compiler-errors dapper

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

使用Reflection从类创建DataTable?

我刚刚学习了Generics,我想知道我是否可以用它来动态地从我的类中构建数据表.

或者我可能会忽略这一点.这是我的代码,我要做的是从我现有的类创建一个数据表并填充它.但是我陷入了思考过程中.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Reflection;
using System.Data;

namespace Generics
{
    public class Dog
    {
        public string Breed { get; set; }
        public string Name { get; set; }
        public int legs { get; set; }
        public bool tail { get; set; }
    }

    class Program
    {
        public static DataTable CreateDataTable(Type animaltype)
        {
            DataTable return_Datatable = new DataTable();
            foreach (PropertyInfo info in animaltype.GetProperties())
            {
                return_Datatable.Columns.Add(new DataColumn(info.Name, info.PropertyType));
            }
            return return_Datatable;
        }

        static void Main(string[] …
Run Code Online (Sandbox Code Playgroud)

.net c# oop reflection

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

将接口扩展为抽象类

我有一个接口(移动)应该移动一些形状.

interface Move { move(); }
abstract class Shape : Move

class Circle : Shape
class Square : Shape
class Triangle : Shape
Run Code Online (Sandbox Code Playgroud)

我的疑问是,我必须有一个移动Shapes的界面,但是只能移动Circle和Triangle,那么我如何从Square"移除"界面?我应该从Shape中删除界面并在Circle和Triangle上手动添加它吗?我有点困惑.希望有人可以帮助我.

c# oop

19
推荐指数
2
解决办法
2900
查看次数

HTTP请求未经授权使用客户端身份验证方案'Ntlm'.从服务器收到的身份验证标头是"Negotiate,NTLM"

我查看了大量的SO文章,甚至是其他网站,但似乎无法使这项服务正常运行.我有一个我想要点击的SOAP服务,它的配置如下:

<system.serviceModel>
    <bindings>
        <basicHttpBinding>
        <binding name="PROVIDERSSoapBinding">
            <security mode="TransportCredentialOnly">
            <transport clientCredentialType="Ntlm" proxyCredentialType="None" realm="" />
            </security>
        </binding>
        </basicHttpBinding>
    </bindings>
    <client>
        <endpoint address="http://xxx.xx.xx.xxx:9011/provider/services/PROVIDERS"
            binding="basicHttpBinding" bindingConfiguration="PROVIDERSSoapBinding"
            contract="ServiceReference1.ProviderRemote" name="PROVIDERS" />
    </client>
</system.serviceModel>
Run Code Online (Sandbox Code Playgroud)

但是,从我的控制台应用程序中点击它时出现以下错误:

HTTP请求未经授权使用客户端身份验证方案'Ntlm'.从服务器收到的身份验证标头是"Negotiate,NTLM".

有人可以帮帮我吗?

.net c# wcf soap

19
推荐指数
3
解决办法
12万
查看次数

msgbox C#中的默认值为No

MessageBoxButtons buttons = MessageBoxButtons.YesNo;
DialogResult result = MessageBox.Show("Are there any other products in the carton?", "Question", buttons, MessageBoxIcon.Question, MessageBoxDefaultButton.Button1);

            if (result == DialogResult.Yes)
            {
                trans.Rollback();
                MessageBox.Show("Please go to the controll room for new packaging", "Message");
                frmHome main = new frmHome(empid);
                main.Show();
                this.Hide();
            }

            if (result == DialogResult.No)
            {
                trans.Commit();
                frmPalletCartonAllocation pca = new frmPalletCartonAllocation(pack, companyIdNo, skuIdNo, UnitsInCarton, UnitsInPack, carton_Code, orderNo, grvIdNo, empid);
                pca.Show();
                this.Hide();
            }
Run Code Online (Sandbox Code Playgroud)

在出现消息框时,"是"按钮会突出显示.我希望"否"按钮突出显示.所以默认'不'.

我该怎么做呢?

.net c# winforms

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

全局异常过滤器或Application_Error都不是捕获未处理的异常

我有一个名为的全局异常过滤器LogErrorAttribute:

public class LogErrorAttribute : IExceptionFilter
{
    private ILogUtils logUtils;

    public void OnException(ExceptionContext filterContext)
    {
        if (this.logUtils == null)
        {
            this.logUtils = StructureMapConfig.Container.GetInstance<ILogUtils>();
        }

        this.logUtils.LogError(HttpContext.Current.User.Identity.GetUserId(), "Unknown error.", filterContext.Exception);
    }
}
Run Code Online (Sandbox Code Playgroud)

它与标准HandleErrorAttribute过滤器一起注册:

filters.Add(new LogErrorAttribute());
filters.Add(new HandleErrorAttribute());
Run Code Online (Sandbox Code Playgroud)

我正在注册这样的过滤器:

FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters);
Run Code Online (Sandbox Code Playgroud)

我也有一个Application_Error后备:

protected void Application_Error()
{
    var exception = Server.GetLastError();
    Server.ClearError();
    var httpException = exception as HttpException;

    //Logging goes here

    var routeData = new RouteData();
    routeData.Values["controller"] = "Error";
    routeData.Values["action"] = "Index";

    if (httpException != null)
    {
        if (httpException.GetHttpCode() …
Run Code Online (Sandbox Code Playgroud)

c# asp.net-mvc exception-handling automapper asp.net-mvc-4

16
推荐指数
1
解决办法
1388
查看次数