小编Joh*_*nes的帖子

如何在我声明的同一行中初始化C#List.(IEnumerable字符串Collection示例)

我正在写我的测试代码,我不想写写:

List<string> nameslist = new List<string>();
nameslist.Add("one");
nameslist.Add("two");
nameslist.Add("three");
Run Code Online (Sandbox Code Playgroud)

我很想写

List<string> nameslist = new List<string>({"one", "two", "three"});
Run Code Online (Sandbox Code Playgroud)

但是{"one","two","three"}不是"IEnumerable string Collection".如何使用IEnumerable字符串Collection在一行中初始化它?

c# collections initialization list

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

什么是标准XUnit报告XML的参考源

我正在编写CUnit的替代品,我希望它能生成XML输出.

我希望输出与jenkins/hudson兼容 - 所以我正在寻找所有XUnit测试所依据的标准xml表单.

有这样的标准吗?

jenkins/hudson可以显示要求的定义在哪里?

xml unit-testing xunit

18
推荐指数
1
解决办法
6432
查看次数

shared_ptr交换线程安全吗?

以下是一些代码段.

std::shared_ptr<int> global(new int(1)); 


void swapper(int x)
{
    std::shared_ptr<int> sp(new int(x));  
    global.swap(sp); 
}
Run Code Online (Sandbox Code Playgroud)

假设我想调用swapper并行线程.这是线程安全的吗?

我知道这个答案.它显示了如果我重新分配值,如何指定指针不是线程安全的global.

我的问题是swap成员函数本身是否是线程安全的.

一方面,shared_ptr的控制块功能是线程安全的.另一方面,我假设我正在切换到控制块的指针,所以它不应该是线程安全的.

有什么联系?是swap线程安全的?

c++ multithreading swap shared-ptr

17
推荐指数
1
解决办法
4802
查看次数

如何将PreProcessorDefinitions设置为msbuild任务的任务

以下内容来自常规的VS2010 C++项目.

    <ClCompile>
      <WarningLevel>Level3</WarningLevel>
      <PrecompiledHeader>Use</PrecompiledHeader>
      <Optimization>MaxSpeed</Optimization>
      <FunctionLevelLinking>true</FunctionLevelLinking>
      <IntrinsicFunctions>true</IntrinsicFunctions>
      <PreprocessorDefinitions>WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
    </ClCompile>
Run Code Online (Sandbox Code Playgroud)

如果我编辑PreprocessorDefinitions我可以设置预处理器使用的定义.我可以在我的代码中看到这个#ifdef等等.

但是如果我使用以下内容

  <Target Name="NormalBuild" Condition=" '$(_InvalidConfigurationWarning)' != 'true' " DependsOnTargets="_DetermineManagedStateFromCL;CustomBeforeBuild;$(BuildDependsOn)" Returns="@(ManagedTargetPath)">
    <ItemGroup>
        <ManagedTargetPath Include="$(TargetPath)" Condition="'$(ManagedAssembly)' == 'true'" />
    </ItemGroup>
      <Message Text="PreprocessorDefinitions: $(PreprocessorDefinitions)" Importance="High" />
  </Target>

  <Target Name="TestBuild" Returns="@(ManagedTargetPath)">
    <MSBuild Projects="demo.vcxproj" Targets="NormalBuild" Properties="PreprocessorDefinitions=THISGETSSETBUTDOESNOTHING"/>
  </Target>
Run Code Online (Sandbox Code Playgroud)

我也可以通过消息看到PreprocessorDefinitions包含我设置的值,Properties="PreprocessorDefinitions=THISGETSSETBUTDOESNOTHING"但我无法控制我的构建使用#ifdef等.如果我使用常规设置并尝试输出PreprocessorDefinitions使用<Message Text="PreprocessorDefinitions: $(PreprocessorDefinitions)"该字段实际上是空白,并不包含预期,<PreprocessorDefinitions>WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>虽然我可以使用用于控制构建的任何一个键使用#ifdef等.

  1. 这是为什么?
  2. 如何通过任务Properties元素传递VS2010 C++项目的PreprocessorDefinitions ?

msbuild

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

WPF绑定到xaml中的多维数组

我很难将XAML字符串表示为链接到多维数组中的特定元素.

DataContext包含以下行:

    private String[] _OneDimension = { "[0]", "[1]" };
    private String[][] _Jagged = { new String[] { "[0,0]", "[0,1]" }, new String[] { "[1,0]", "[1,1]" } };
    private String[,] _TwoDimension = { { "[0,0]", "[0,1]" }, { "[1,0]", "[1,1]" } };

    public String[] OneDimension { get { return _OneDimension; } }
    public String[][] Jagged { get { return _Jagged; } }
    public String[,] TwoDimension { get { return _TwoDimension; } }
Run Code Online (Sandbox Code Playgroud)

XAML包含以下行:

    <StackPanel>
        <Button Content="{Binding OneDimension[1]}" Width="100" Height="50" /> …
Run Code Online (Sandbox Code Playgroud)

data-binding wpf binding

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

用户在数组/集合中以及每个循环中定义的类型

VBA在弹出窗口中显示我不允许迭代具有用户定义类型的数组.我写了一些代码,并想知道我如何解决这个问题.这是一个迷你的例子,专注于我想要做的事情.

Option Explicit

Type Info
    source As String
    destination As String
End Type

Sub specialCopy()
    Dim target As Variant
    Dim AllTargets() As Info: AllTargets = SetAllTargets()
    For Each target In AllTargets
        CopyValues (target)
    Next
End Sub

Function SetAllTargets() As Info()
    Dim A As Info: A = SetInfo("A1", "B1")
    Dim B As Info: B = SetInfo("A2", "B2")
    Dim AllTargets() As Info
    Set AllTargets = Array(A, B)
End Function

Function SetInfo(source As String, target As String) As Info
    SetInfo.source = source
    SetInfo.destination …
Run Code Online (Sandbox Code Playgroud)

foreach vba types

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

"cout <<(a,b)"的输出是什么?为什么?

可以将布尔表达式与逗号分隔符组合在一起.我在代码中看到了它,我不确定这会解决什么问题.我写了一些示例代码.

int BoolStatement(void)
{
    using std::cout;
    using std::endl;

    cout << "(0, 0) => " << (0, 0) << endl;
    cout << "(0, 1) => " << (0, 1) << endl;
    cout << "(1, 0) => " << (1, 0) << endl;
    cout << "(1, 1) => " << (1, 1) << endl;
    cout << "(0, 0) => " << (0, 0) << endl;
    cout << "(0, 3) => " << (0, 3) << endl;
    cout << "(5, 0) => …
Run Code Online (Sandbox Code Playgroud)

c++ comma

8
推荐指数
3
解决办法
3218
查看次数

是否有std :: chrono中的工具可以帮助注入system_clock进行单元测试

我依赖可能会或可能不会响应的硬件.因此,我经常最终编写具有超时功能.系统时间是脆性单元测试的已知来源,因此注入受控且稳定的时间似乎是测试的好主意.

我想知道std :: chrono中是否有任何设施可以帮助解决这个问题.我看到的替代方法是围绕系统时间编写一个包装器并依赖于该适配器.

以下是包装器外观的最小示例.

#pragma once
#include <memory>
#include <chrono>
#include <thread>
#include <iostream>

using std::chrono::system_clock;
using std::chrono::milliseconds;
using std::shared_ptr;
using std::make_shared;

class Wrapped_Clock
{
public:
    virtual system_clock::time_point Now() { return system_clock::now(); }
    virtual void Sleep(milliseconds ms) { std::this_thread::sleep_for(ms); }
};

class Mock_Clock : public Wrapped_Clock
{
private:
    system_clock::time_point now;
public:
    Mock_Clock() : now(system_clock::now()){}
    ~Mock_Clock() {}
    system_clock::time_point Now() { return now; }
    void Sleep(milliseconds ms) { }
};

class CanTimeOut
{
private:
    shared_ptr<Wrapped_Clock> sclock;
public:
    CanTimeOut(shared_ptr<Wrapped_Clock> sclock = make_shared<Wrapped_Clock>()) …
Run Code Online (Sandbox Code Playgroud)

c++ unit-testing systemtime c++11 c++-chrono

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

VS2015在VC_IncludePath中修复路径问题

尝试编译一个简单的hello world c ++程序时遇到问题.

#include <iostream>

int main()
{
    std::cout << "hello world" << std::endl;
    return 0;
}
Run Code Online (Sandbox Code Playgroud)

其中的错误是:
无法打开源文件"errno.h"

使用console(c:\> dir errno.h /s)快速搜索显示该文件位于多个目录中:
C:\ LegacyApp\VisualStudio2013\VC\crt\src
C:\ LegacyApp\VisualStudio2013\VC\include
C:\ Program Files(x86)\ Microsoft Visual Studio 11.0\VC\crt\src
C:\ Program Files(x86)\ Microsoft Visual Studio 11.0\VC\include
C:\ Program Files(x86)\ Windows Kits\10\Include\10.0.10150.0\ucrt

我的项目默认属性包括以下宏: $(VC_IncludePath);$(WindowsSDK_IncludePath);

这解析为:
C:\ LegacyApp\VisualStudio2015\VC\include
C:\ LegacyApp\VisualStudio2015\VC\atlmfc\include
C:\ Program Files(x86)\ Windows Kits\10\Include\10.0.10240.0\ucrt
C:\程序文件(x86)\ Windows Kits\8.1 \包含\ um
C:\ Program Files(x86)\ Windows Kits\8.1\Include\shared
C:\ Program Files(x86)\ Windows Kits\8.1\Include\winrt

C:\Program Files (x86)\Windows Kits\10\Include\10.0.10240.0\ucrt …

c++ visual-studio-2015 universal-crt

7
推荐指数
2
解决办法
6379
查看次数

使用Int64进行位移

需要移位Int64变量.我正在从数据库文件中解析伪数学函数.变量是uint32或int32所以我确实将它们放入Int64中以平等地处理它们而不会丢失任何东西.在我的一个treenodes中,我需要将Int64移位.

不幸的是,移位运算符不适用于Int64.是否有一种我不知道的比特移位Int64的标准方法?

//Int32 Example works
int a32 = 1;
int b32 = 2;
int c32 = a32 >> b32;

//Int64 Example does not compile
Int64 a64 = 1;
Int64 b64 = 2;
Int64 c64 = a64 >> b64; //invalid operator
Run Code Online (Sandbox Code Playgroud)

.net c# bit-shift int64

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