小编ama*_*ha4的帖子

在 Markdown 中显示 .csv 文件的内容

我有一个 C# 解决方案,其中包含通过文本模板从 .csv 文件自动生成的单元测试。

.csv 文件是任何团队成员都可以参考的好表,并且可以作为系统的动态文档。

我们正在运行 TFS 2015,我知道可以结合使用 Markdown 来提供清晰的系统文档。

是否可以使用 Markdown 在表格中显示 .csv 文件(存储在 TFS 服务器上)的内容?那么,如果编辑 .csv 文件,Markdown 页面会反映这一点吗?

markdown tfs unit-testing

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

使用类字段作为参数时抛出 ArgumentOutOfRangeException 时的 CA2208

验证正确的枚举值时,我抛出 ArgumentOutOfRangeException:

internal class MyClass : IMyInterface
{
    private readonly MyEnum _myEnum;

    public MyClass(MyEnum myEnum) => _myEnum = myEnum;

    public String MyString
    {
        get
        {
            switch (_myEnum)
            {
                case MyEnum.A:
                    return "A";
                case MyEnum.B:
                    return "B";
                default:
                    throw new ArgumentOutOfRangeException("_myEnum");
            }
        }
    }
}
Run Code Online (Sandbox Code Playgroud)

我在构建时遇到 CA2208 错误:

CA2208 方法“MyCLass.MyString.get()”将“_myEnum”作为“paramName”参数传递给“ArgumentOutOfRangeException”构造函数。将此参数替换为方法的参数名称之一。请注意,提供的参数名称应具有与方法上声明的完全相同的大小写。

我不确定为什么这条规则如此严格,因为参数必须是方法的参数之一,而且我不能使用类字段。

我正在考虑取消此警告,但我宁愿调查为什么会发出此警告。

注意:MyString 属性是 IMyInterface 的一部分,不能将此枚举值作为参数。

.net c# code-analysis

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

使用SQL语句的结果填充任何ArrayList

我有以下代码,它采用SQL语句(字符串),将结果加载到ArrayList(organisationList),它是组织的集合:

public void FillDataGridView(DataGridView grid, string SQLCommand)
{
    SqlCommand dataCommand = new SqlCommand();
    dataCommand.Connection = dataConnection;
    dataCommand.CommandType = CommandType.Text;
    dataCommand.CommandText = SQLCommand;

    SqlDataReader dataReader = dataCommand.ExecuteReader();

    while (dataReader.Read())
    {
        Organisation org = new Organisation();

        org.OrganisationId = (int)dataReader["OrganisationId"];
        org.OrganisationName = (string)dataReader["OrganisationName"];

        organisationList.Add(org);
    }

    grid.DataSource = organisationList;
    dataReader.Close();
}
Run Code Online (Sandbox Code Playgroud)

我想调整此方法以填充传入其中的ArrayList.

我是否可以将列表传递给方法,并具有以下内容:

public void FillArrayList(DataGridView grid, SqlDataReader reader, ArrayList list)
{
    //Fill the list with the contents of the reader
    while (reader.Read())
    {
        Object  obj = new Object

        for(int i; i = 0; …
Run Code Online (Sandbox Code Playgroud)

.net c# sql arraylist sqldatareader

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

WPF MVVM - 从祖先视图模型绑定到属性

我有一组类似于以下内容的视图/视图模型:

CustomDialogView
  CustomView
    CustomListView
      CustomControl
        -SomeCustomProperty
Run Code Online (Sandbox Code Playgroud)

这些视图中的每一个都绑定到适当的视图模型。

我正在尝试将 SomeCustomProperty 绑定到 CustomDialogView 视图模型上的属性。

做这个的最好方式是什么?我尝试了一些事情,其中​​最有希望的似乎是通过 RelativeSource FindAncestor 设置此属性的绑定,例如:

<CustomControl
    SomeCustomProperty="{
        Binding RelativeSource={RelativeSource FindAncestor,
        AncestorType={x:Type sourcePath:CustomDialogViewModel}},
        Path=SomeCustomProperty,
        Mode=OneWay/>
</CustomControl>
Run Code Online (Sandbox Code Playgroud)

但我在这里根本没有任何约束力。

我不确定它是否有任何意义,但 CustomListView 是由工厂填充的。

c# data-binding wpf relativesource mvvm

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