C# Stylecop发布SA1201:类中项的顺序
在Stylecop警告SA1201之后,我对类进行了如下修改C# Stylecop发布SA1201:类中项的顺序,c#,asp.net,stylecop,C#,Asp.net,Stylecop,在Stylecop警告SA1201之后,我对类进行了如下修改 /// <summary> /// Class Data /// </summary> public class DataClass { /// <summary> /// Gets or sets Id /// </summary> public string Id { get { return this.id; }
/// <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;
}
//
///类数据
///
公共类数据类
{
///
///获取或设置Id
///
公共字符串Id
{
获取{返回this.id;}
设置{this.id=value;}
}
///
///获取或设置名称
///
公共字符串名
{
获取{返回this.name;}
设置{this.name=value;}
}
///
///声明变量名
///
私有字符串名称;
///
///声明变量id
///
私有字符串id;
}
仍然显示相同的错误
“所有属性必须放在所有字段之后”我认为您将属性和字段混为一谈。属性使用getter和setter,而字段是“传统”变量 您的代码应该如下所示:
/// <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; }
}
}
//
///类数据
///
公共类数据类
{
///
///声明变量名
///
私有字符串名称;
///
///声明变量id
///
私有字符串id;
///
///获取或设置Id
///
公共字符串Id
{
获取{返回this.id;}
设置{this.id=value;}
}
///
///获取或设置名称
///
公共字符串名
{
获取{返回this.name;}
设置{this.name=value;}
}
}
你已经把它倒过来了<在id
和name
之前的code>id和name
。