Attribute in .net
-
Why we need Attribute in .net application ? Please give any real time example. Thanks in Advance
-
Why we need Attribute in .net application ? Please give any real time example. Thanks in Advance
Attributes allow us to decorate something, e.g. a class, with something that indicates to a piece of calling code that this particular thing has certain behaviour. While the operation can appear magical at times, e.g. how does marking a class as Serializable mean it can be serialized, there is always a piece of code at the other side that is checking to see if the attribute exists and acting on it if it's present. Serialization is a great example of the practical use of attributes. As well as marking a class as being capable of serialization, we can use additional attributes to say that certain types in that class should not be serialized. Then, when you attempt to serialize the class in your code, the underlying serialization engine determines that the class can be serialized but it has to ignore certain members in it.
-
Why we need Attribute in .net application ? Please give any real time example. Thanks in Advance
What else you suggest ? Whats problem with Attribute ?
-
Attributes allow us to decorate something, e.g. a class, with something that indicates to a piece of calling code that this particular thing has certain behaviour. While the operation can appear magical at times, e.g. how does marking a class as Serializable mean it can be serialized, there is always a piece of code at the other side that is checking to see if the attribute exists and acting on it if it's present. Serialization is a great example of the practical use of attributes. As well as marking a class as being capable of serialization, we can use additional attributes to say that certain types in that class should not be serialized. Then, when you attempt to serialize the class in your code, the underlying serialization engine determines that the class can be serialized but it has to ignore certain members in it.