我知道属性非常有用。有一些预定义的属性,例如[Browsable(false)],它允许您在财产选项卡中隐藏财产。下面是一个解释属性的好问题:.NET中的属性是什么?

您在项目中实际使用的预定义属性(及其名称空间)是什么?


当前回答

[System.Security.Permissions.PermissionSetAttribute]允许使用声明性安全性将PermissionSet的安全操作应用于代码。

// usage:
public class FullConditionUITypeEditor : UITypeEditor
{
    // The immediate caller is required to have been granted the FullTrust permission.
    [PermissionSetAttribute(SecurityAction.LinkDemand, Name = "FullTrust")]
    public FullConditionUITypeEditor() { }
}

其他回答

如果项目不在您的解决方案中,[EditorBrowsable(EditorBrowsableState.Never)]允许您对IntelliSense隐藏财产和方法。非常有助于隐藏流畅接口的无效流。您希望多长时间使用GetHashCode()或Equals()?

对于MVC,[ActionName(“Name”)]允许您使用相同的方法签名进行Get操作和Post操作,或者在操作名称中使用破折号,否则,如果不为其创建路由,就无法实现这一点。

它的名称不好,在框架中也不受支持,不应该需要参数,但这个属性是不可变类的有用标记:

[ImmutableObject(true)]
[TypeConverter(typeof(ExpandableObjectConverter))]

告诉设计器展开财产,这些属性是(控件的)类

[Obfuscation]

指示混淆工具对程序集、类型或成员执行指定的操作。(尽管通常使用程序集级别[Assembly:ObfuscateAssemblyAttribute(true)]

我最近一直在使用[DataObjectMethod]。它描述了方法,因此您可以将类与ObjectDataSource(或其他控件)一起使用。

[DataObjectMethod(DataObjectMethodType.Select)] 
[DataObjectMethod(DataObjectMethodType.Delete)] 
[DataObjectMethod(DataObjectMethodType.Update)] 
[DataObjectMethod(DataObjectMethodType.Insert)] 

更多信息

如果我要进行代码覆盖率爬网,我认为这两个将是最好的:

 [Serializable]
 [WebMethod]