【问题标题】:Class and properties attributes类和属性属性
【发布时间】:2013-03-11 08:38:21
【问题描述】:

我只是下载一个入门项目用于学习目的。 在这个我发现了一些关于类和属性的标签。有人可以遮光这些吗?比如我们为什么要使用它们?

[Serializable]
    public partial class RoleToPermission
    {
        [DataMember]
        [ColumnAttribute(DbType = "int")]
        [AddEditDelete(Ignore=true)]
        public int RolePermissionID { get; set; }

        [DataMember]
        [ColumnAttribute(DbType = "int")]
        [AddEditDelete(Add = false, Delete = true)]
        public int RoleID { get; set; }

【问题讨论】:

标签: c# winforms


【解决方案1】:

Attributes 用于将附加信息附加到程序实体上,例如类、属性、字段或方法。在运行时,感兴趣的代码可以使用反射检索此信息。

例如,当您使用DataContractSerializer 序列化对象时,序列化程序将查找带有[DataMember] 属性标记的任何字段或属性。所以[DataMember] 属性允许你声明哪些字段和属性应该被序列化。

存在一些useful attributes,您也可以将write your own attributes 用于其他目的。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2011-11-24
    • 2014-03-05
    • 1970-01-01
    • 2011-03-18
    • 2018-04-14
    • 1970-01-01
    相关资源
    最近更新 更多