On Field/Property Level - The call is intercepted to the field/property, but I cannot tell if this field or property is marked with my desired attribute. GetCustomAttributes() list on a 'Field or Property' call interception always returns empty.
With a field interception, you get a message object for the Object.FieldSetter (or FieldGetter) method. Of course, these methods do not have any custom attributes declared on them, especially not those you declared on the field. However, you can access the actual FieldInfo, which returns your attributes, via Reflection: IMethodMessage call = ...; FieldInfo field = Type.GetType(call.Args[0].ToString()).GetField(call.Args[1].ToString(), BindingFlags.Instance | BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic); object[] attributes = field.GetCustomAttributes(false); Console.WriteLine(attributes.Length); (Of course, in reality, you should check for errors.) Similarly, for property interceptions, you get the property's get or set method. Although it is possible to attach custom attributes to these methods, you've probably declared them on the surrounding property, so you need to call GetCustomAttributes on the respective PropertyInfo object. As far as I recall, there's no easy way to go from a property's get/set method to the PropertyInfo object - you have to remove the "get_" or "set_" string from the method name and look up the PropertyInfo manually from the method's declaring type. (If I'm mistaken and there is an easier way, please somebody correct this.) Fabian =================================== This list is hosted by DevelopMentorĀ® http://www.develop.com View archives and manage your subscription(s) at http://discuss.develop.com
