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

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


当前回答

我发现[DefaultValue]非常有用。

其他回答

[Serializable]始终用于将对象序列化到外部数据源(如xml)或从远程服务器序列化对象。在这里了解更多信息。

[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() { }
}

我的投票将是有条件的

[Conditional("DEBUG")]
public void DebugOnlyFunction()
{
    // your code here
}

您可以使用它添加具有高级调试功能的函数;与Debug.Write类似,它只在调试构建中调用,因此允许您将复杂的调试逻辑封装在程序的主流之外。

[DeploymentItem(“myFile1.txt”)]DeploymentItem上的MSDN文档

如果您正在对文件进行测试或将该文件用作测试的输入,那么这非常有用。

我发现[DefaultValue]非常有用。