Reputation: 89
I am working on building a custom declarative security attribute, similar to the PrincipalPermissionAttribute. After doing some research on the Attribute architecture within the .net Framework, attributes are instantiated only when Type.GetCustomAttributes is called. See Here, And Here
So how is the PrincipalPermissionAttribute able to assert security actions at runtime if the method attributes were never instantiated? I cannot find any documentation on how the PrincipalPermissionAttribute actually works. Thanks.
Upvotes: 2
Views: 1867
Reputation: 21002
The CLR actually looks for and triggers runtime execution of instances of attributes that inherit from System.Security.Permissions.CodeAccessSecurityAttribute. If you want to build a declarative security attribute without resorting to AOP extensions, you pretty much have to inherit from this class.
Upvotes: 3