如果你说的是给class 添加Attribute 那么你可以试试用 ctrl+k+ ctrl+x 导出 snippt 然后选择C#的Attribute,就会出现Attribute模板了。效果如下: [global::System.AttributeUsage(AttributeTargets.All, Inherited = false, AllowMultiple = true)] sealed class MyAttribute : Attribute { // See the attribute guidelines at // http://go.microsoft.com/fwlink/?LinkId=85236 readonly string positionalString; // This is a positional argument public MyAttribute(string positionalString) { this.positionalString = positionalString; // TODO: Implement code here throw new NotImplementedException(); } public string PositionalString { get; private set; } // This is a named argument public int NamedInt { get; set; } }
那么你可以试试用 ctrl+k+ ctrl+x 导出 snippt 然后选择C#的Attribute,就会出现Attribute模板了。效果如下:
[global::System.AttributeUsage(AttributeTargets.All, Inherited = false, AllowMultiple = true)]
sealed class MyAttribute : Attribute
{
// See the attribute guidelines at
// http://go.microsoft.com/fwlink/?LinkId=85236
readonly string positionalString; // This is a positional argument
public MyAttribute(string positionalString)
{
this.positionalString = positionalString; // TODO: Implement code here
throw new NotImplementedException();
} public string PositionalString { get; private set; } // This is a named argument
public int NamedInt { get; set; }
}
那么直接在字段(field)上右键重构-->封装字段就可以了。