Pseudo custom attributes are custom attributes but are treated by the compiler differently than other custom attributes. The storage and retrieval mechanism is different than the other custom attributes. This is done because the pseudo custom attributes are frequently used and it requires space-efficient storage and faster check at runtime. Below are some points which are worth understanding about pseudo attributes:
- Pseudo attributes are laid out in the assembly metadata differently than the other custom attributes. For e.g. Presence of [Serializable] attribute on a type is laid out in the assembly metadata by making a bit on or off. [Serializable] attribute is the one of the most common pseudo custom attributes and it is stored in this manner for the purpose of storage and retrieval efficiency. They are either laid out as bit field or a flag which is unlike other custom attributes that are laid out as blobs.
- Some of the Pseudo Custom attributes are not reported by the overloads of Type.GetCustomAttributes overloaded functions.
For e.g. Presence of [StructLayout] attribute is not reported by the GetCustomAttributes methods on the Type class.
The above points helps when you are developing an application which involves heavy reading of metadata using reflection.
No comments:
Post a Comment