1

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

1 Answer 1

2

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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.