DDR
DDR

Reputation: 1322

Class and properties attributes

i just download a starter project for learning purpose. in this i found some tags on class as well as on properties. Can some one shade light of these? like why we use them ?

[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; }

Upvotes: 1

Views: 193

Answers (1)

Eren Ersönmez
Eren Ersönmez

Reputation: 39085

Attributes are used to attach additional information onto program entities, such as a class, a property, a field or a method. At run-time, the interested code can retrieve this information using reflection.

For instance, when you use a DataContractSerializer to serialize an object, the serializer will look for any field or property that is tagged with a [DataMember] attribute. So the [DataMember] attribute allows you to declare which fields and properties should be serialized.

There exists some useful attributes, and you can also write your own attributes for other purposes.

Upvotes: 2

Related Questions