Custom attribute missing when using PostSharp based attributes -


newbie postsharp. consider following code:

using system; using postsharp.aspects;  namespace postsharp1 {      [attributeusage(attributetargets.property)][serializable]public class field1attribute : system.attribute { }     [attributeusage(attributetargets.property)][serializable]public class field2attribute : locationinterceptionaspect { }      public class person {         [field1][field2]public string name { get; set; }     }      class program {          static void main(string[] args) {              var friend = new person();             friend.name = "fred bloggs";              var properties = friend.gettype().getproperties();             console.writeline("properties: " + properties.length);             var count1 = 1;             foreach (var property in properties) {                 var customattributes = property.getcustomattributes(false);                 console.writeline("  property #" + count1++ + ": " + property.name + ", # custom attributes = " + customattributes.length);                 var count2 = 1;                 foreach (system.attribute customattribute in customattributes) {                     console.writeline("    attribute #" + count2++ + ": " + customattribute.tostring());                 }             }         }      }  } 

a made-up example uses reflection list custom attributes on properties of small person class.

the program lists field1attribute (based upon system.attribute) field2attribute appears have been stripped out it's not listed.

just trying understand mechanism here , why locationinterceptionaspect derived attribute missing.

strange how writing question allows research answer. "by-design" - aspects (which derived system.attribute) removed after have been applied. kind of makes sense postsharp build time. however, it's possible prevent them being removed covered in documentation:

1.1.5. reflecting aspect instances @ runtime

attribute multicasting has been designed mechanism add aspects program. of time, custom attribute representing aspect can removed after aspect has been applied. default, if add aspect program , @ resulting program using disassembler or system. reflection, not find these corresponding custom attributes.

if need aspect (or other multicast attribute) reflected system.reflection or other tool, have set multicastattributeusageattributepersistmetadata property true. instance:

[multicastattributeusage( multicasttargets.class, persistmetadata = true )] public class tagattribute : multicastattribute { public string tag; } 

Comments

Popular posts from this blog

asp.net mvc - SSO between MVCForum and Umbraco7 -

Python Tkinter keyboard using bind -

ubuntu - Selenium Node Not Connecting to Hub, Not Opening Port -