小编Jul*_*ner的帖子

为什么在C++中的容器中存储引用(而不是指针)不起作用?

在我的程序中,我有一个STL集.

set<string> myStrings;
Run Code Online (Sandbox Code Playgroud)

为了提高代码的效率,我把它改为hold,只有指针.(我不需要存储实际的字符串副本.)

set<string*> myStrings;
Run Code Online (Sandbox Code Playgroud)

我已经读过,在可能的情况下用指针替换指针是一个好习惯.(当然,仅当不需要指针的实际功能时.)

set<string&> myStrings;
Run Code Online (Sandbox Code Playgroud)

但后者给了我很多编译器错误.为什么不能将引用用作容器元素?

c++ containers stl reference

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

如何配置Git以信任来自Windows证书存储区的证书?

目前.gitconfig,我的用户目录中有以下条目.

...
[http]
    sslCAInfo=C:\\Users\\julian.lettner\\.ssh\\git-test.pem
...
Run Code Online (Sandbox Code Playgroud)

这设置了在与git服务器交互时使用的证书(我公司的git服务器所需).

但是现在我无法克隆其他存储库(例如GitHub上的公共存储库),因为客户端始终使用被其他服务器拒绝的已配置证书.

我如何规避此认证问题?我可以配置Git使用Windows证书存储区进行身份验证吗?

windows git ssl-certificate certificate-store

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

为什么属性的属性必须是可读的?

请考虑以下属性.

internal class NiceAttribute : Attribute
{
  private string _stuff;

  public string Stuff
  {
    set { _stuff = value; }
  }
}
Run Code Online (Sandbox Code Playgroud)

当我尝试使用该属性时[Nice(Stuff = "test")],编译器会给出以下错误.

'Stuff'不是有效的命名属性参数.命名属性参数必须是非readonly,static或const的字段,或者 是公共而非静态的读写属性.

要求财产可读的理由是什么?


更新
我将尝试绘制我的用例,以便在属性上具有只写属性.

interface ISettingsBuilder
{
  Settings GetSettings();
}

class SettingsAttribute : Attribute, ISettingsBuilder
{
  private readonly IDictionary<string, object> _settings =
    new Dictionary<string, object>();

  public Settings GetSettings()
  {
    // Use _settings to create an immutable instance of Settings
  }

  public string Stuff
  {
    set { _settings["Stuff"] = …
Run Code Online (Sandbox Code Playgroud)

c# attributes compiler-errors properties

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

获取Xunit中运行测试的名称

使用Xunit,我如何获得当前运行的测试的名称?

  public class TestWithCommonSetupAndTearDown : IDisposable
  {
    public TestWithCommonSetupAndTearDown ()
    {
      var nameOfRunningTest = "TODO";
      Console.WriteLine ("Setup for test '{0}.'", nameOfRunningTest);
    }

    [Fact]
    public void Blub ()
    {
    }

    public void Dispose ()
    {
      var nameOfRunningTest = "TODO";
      Console.WriteLine ("TearDown for test '{0}.'", nameOfRunningTest);
    }
  }
Run Code Online (Sandbox Code Playgroud)

编辑:
特别是,我正在寻找NUnits TestContext.CurrentContext.Test.Name属性的替代品.

.net c# tdd xunit

15
推荐指数
2
解决办法
4492
查看次数

在Ninject中注入接口数组

请考虑以下代码.

public interface IFoo { }


public class Bar
{
    public Bar(IFoo[] foos) { }
}


public class MyModule : NinjectModule
{
    public override void Load()
    {
        Bind<IFoo[]>().ToConstant(new IFoo[0]);
        // ToConstant() is just an example
    }
}


public class Program
{
    private static void Main(string[] args)
    {
        var kernel = new StandardKernel(new MyModule());
        var bar = kernel.Get<Bar>();
    }
}
Run Code Online (Sandbox Code Playgroud)

当我尝试运行该程序时,我得到以下异常.

激活IFoo时出错
没有匹配的绑定可用,并且该类型不可自我绑定.
激活路径:
2)将依赖关系IFoo注入到Bar
1 类型的构造函数的参数foo中.请求Bar

如何在Ninject中注入/绑定到数组?

谢谢你的时间.

编辑:
我的应用程序导入由第三方组件创建的数据.导入过程应用不同类型的过滤器(例如,不同过滤器接口的实现).过滤规则经常发生变化,但过于复杂,无法使用纯配置(和主过滤器).

我想尽可能简单地添加/编辑过滤器.我所拥有的是一个所有过滤器实现所在的程序集.我尝试将每个过滤器接口绑定到以下方法(它提供该过滤器类型的每个实现的实例).基本上我想避免在添加/删除过滤器类时更改我的Ninject模块.

    private IEnumerable<TInterface> GetInterfaceImplementations<TInterface>(IContext context)
    {
        return GetType().Assembly.GetTypes()
            .Where(t => …
Run Code Online (Sandbox Code Playgroud)

.net c# arrays dependency-injection ninject

14
推荐指数
2
解决办法
6012
查看次数

编译器不推导出模板参数(map std :: vector - > std :: vector)

我有以下模板.

template<typename T, typename U>
std::vector<U> map(const std::vector<T> &v, std::function<U(const T&)> f) {
    std::vector<U> res;
    res.reserve(v.size());
    std::transform(std::begin(v), std::end(v), std::end(res), f);
    return res;
}
Run Code Online (Sandbox Code Playgroud)

当我在我的代码中使用它时,我指定了模板参数.为什么编译器无法为我推断出这个?如何更改模板定义以使其工作?

vector<int> numbers = { 1, 3, 5 };

// vector<string> strings = map(numbers, [] (int x) { return string(x,'X'); });

vector<string> strings = map<int, string>(numbers, [] (int x) { return string(x,'X'); });
Run Code Online (Sandbox Code Playgroud)

可运行代码:http://ideone.com/FjGnxd

这个问题中的原始代码来自:std :: transform-like函数返回转换后的容器

c++ templates vector std c++11

9
推荐指数
1
解决办法
801
查看次数

以编程方式创建流程图

我想用.NET/C#可视化HVAC系统的组件和连接.图表将包含一些不同的组件及其连接.它们不必遵守任何正式标准,并且应该与附图相似.此外,用户应该能够选择单个组件/连接(以便我可以显示其他数据).

你会使用哪个免费的绘图/图表库?为什么?

谢谢你的时间.

暖通空调系统http://img638.imageshack.us/img638/6382/examplee.png 暖通空调系统http://img260.imageshack.us/img260/4171/example2.png

.net c# charts drawing flowchart

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

WPF TreeView 数据绑定以隐藏/显示展开/折叠图标

我实现了一个 WPF 按需加载树视图,就像这篇(非常好的)文章中描述的那样。在提到的解决方案中,使用一个虚拟元素来保留展开+图标/树状视图项的行为。当用户单击扩展器时,虚拟项目将替换为真实数据。

我想通过向public bool HasChildren { get { ... } }我的 backing添加一个属性来优化模型TreeNodeViewModel。

问题:
如何绑定此属性以隐藏/显示展开图标(在 XAML 中)?我找不到合适的触发器/设置器组合。
(INotifyPropertyChanged 已正确实施。)

谢谢你的时间。

更新 1:
我想使用我的属性public bool HasChildren 而不是使用虚拟元素。
确定一个物品是否有孩子的成本有点高,但仍然比去取孩子便宜得多。

data-binding wpf treeview expand collapse

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

ASP.NET MVC 5:定义跨控制器的路由顺序 (RouteAttribute)

该RouteAttribute("abc", Order = 2)排序仅似乎在控制器内推崇:当在同一个控制器定义以下方法,我得到预期的行为,即Method1优先级,Method2则永远不会调用。

[Route("abc", Order = 1)]
public ActionResult Method1() { ... }

[Route("abc", Order = 2)]
public ActionResult Method2() { ... }
Run Code Online (Sandbox Code Playgroud)

如果我在两个单独的控制器中定义这些方法,我会得到一个不明确的路由异常: InvalidOperationException: Multiple controller types were found that match the URL. This can happen if attribute routes on multiple controllers match the requested URL.

是否可以使用属性路由定义跨控制器的顺序?

编辑 1:当分布在多个控制器上时,似乎即使在一个控制器内具有隐式排序的路由也是模棱两可的。以下在一个控制器中是可以的(通配符之前的文字),但如果放入不同的控制器中会引发异常。

[Route("details/abc")]
[Route("details/{product}")]
Run Code Online (Sandbox Code Playgroud)

这让我认为它是设计使控制器保持专注并强制在同一控制器中定义类似的路由。

编辑2:

这些是我真正想要使用的路线。我想把它们放到不同的控制器中,因为它们做不同的事情。它们的区别在于前缀。

[Route("reactive/monitor")]
[Route("{tier}/monitor")]
Run Code Online (Sandbox Code Playgroud)

c# asp.net-mvc asp.net-mvc-routing routeattribute asp.net-mvc-5

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

通过Reflection.Emit生成代理仅在启动调试时有效

大学的一项任务是使用Reflection.Emit实现一个简单的代理生成器/拦截器机制.我想出了以下程序.

看来工作的Visual Studio调试模式里面就好了[F5](调试- >启动调试),但是当没有调试开始崩溃的大部分时间[Ctrl + F5](调试- >启动不调试).

这两种模式有什么区别?(我没有提到Debug <> Release模式).问题出现在多台机器/设置上(Win XP SP3 32位和64位,Windows 7 32位).

单击以获取pastebin.

// The proxy generator; I assume that the error is buried along the lines emitting the IL code
public static class ProxyGenerator
{
    public static T Create<T>(object obj, IInterception interception)
    {
        Type type = obj.GetType();

        TypeBuilder proxy = DefineProxy(type);

        FieldBuilder wrappedField = DefinePrivateField(proxy, "wrappedObject", type);
        FieldBuilder interceptionField = DefinePrivateField(proxy, "interception", interception.GetType());

        DefineConstructor(proxy, wrappedField, interceptionField);
        DefineInterfaceMethods(type, proxy, wrappedField, …
Run Code Online (Sandbox Code Playgroud)

reflection.emit .net-4.0 visual-studio-2010

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