在Stylecop警告SA1201之后我修改了类如下
/// <summary>
/// Class Data
/// </summary>
public class DataClass
{
/// <summary>
/// Gets or sets Id
/// </summary>
public string Id
{
get { return this.id; }
set { this.id = value; }
}
/// <summary>
/// Gets or sets Name
/// </summary>
public string Name
{
get { return this.name; }
set { this.name = value; }
}
/// <summary>
/// Declare variable name
/// </summary>
private string name;
/// <summary>
/// Declare variable id
/// </summary>
private string id;
}
仍然显示相同的错误 “所有属性必须放在所有字段之后”
答案 0 :(得分:2)
我认为你混淆了属性和领域。属性使用getter和setter,而fields是“传统”变量。
https://msdn.microsoft.com/library/x9fsa0sw.aspx
您的代码应如下所示:
/// <summary>
/// Class Data
/// </summary>
public class DataClass
{
/// <summary>
/// Declare variable name
/// </summary>
private string name;
/// <summary>
/// Declare variable id
/// </summary>
private string id;
/// <summary>
/// Gets or sets Id
/// </summary>
public string Id
{
get { return this.id; }
set { this.id = value; }
}
/// <summary>
/// Gets or sets Name
/// </summary>
public string Name
{
get { return this.name; }
set { this.name = value; }
}
}