The problem is, there's no link from MethodInfo of property Getter/Setter to PropertyInfo, so you either have to match from the other side (get ALL propertyInfos on the type and then check if the method you have is defined for any of them... which is costly) or use strings, which is ugly but works faster (a lot).
You can however do it once in IInterceptorSelector, and feed this to an immutable interceptor using interceptor per method approach. 2009/9/10 Jonathon Rossi <[email protected]>: > Oh yer. Sorry I missed that. > > I am not aware of any solution without the ugly substring call. Other people > came to the same conclusion: > http://stackoverflow.com/questions/520138/finding-the-hosting-propertyinfo-from-the-methodinfo-of-getter-setter > > On Thu, Sep 10, 2009 at 3:08 PM, James Curran <[email protected]> > wrote: >> >> Actually, in the donjon thread you cite: >> >> Assert.IsTrue(Attribute.IsDefined(nameProperty, >> typeof(FixedFieldAttribute), true)); >> >> The problem is, I don't have the PropertyInfo or even the property Name. >> >> >> On Thu, Sep 10, 2009 at 12:44 AM, Jonathon Rossi<[email protected]> >> wrote: >> > You can do this as I mentioned in DYNPROXY-109: >> > Attribute.IsDefined(methodInfo, typeof(FixedFieldAttribute), true) >> > >> > The static methods on the Attribute class works at a high level language >> > level (e.g. C#) rather than an IL/metadata level. >> > >> > On Thu, Sep 10, 2009 at 12:47 PM, James Curran <[email protected]> >> > wrote: >> >> >> >> Ok, I followed the debate over DYNPROXY-ISSUE-109. Now that I >> >> actually need the ability, it seems a bit screwy. Here's my >> >> situation: >> >> >> >> I've an interface like this (it will be user-defined in practice; this >> >> is an example) >> >> public interface Dir >> >> { >> >> [FixedField(0, 20)] >> >> DateTime ModDate { get; } >> >> >> >> [FixedField(29, 9)] >> >> int Size { get; } >> >> >> >> [FixedField(38, 40)] >> >> string Name { get; } >> >> } >> >> >> >> The goal is to create a proxy class with automatic implements those >> >> properties, base on the information in the Attributes. >> >> >> >> Now, if I followed this correctly, just to identify that a getter >> >> method I'm given the option of intercepting (get_Name, for instance) >> >> has the attribute, I must write: >> >> >> >> methodInfo.DeclaringType.GetProperty(methodInfo.Name.Substring >> >> (4)).IsDefined(typeof(FixedFieldAttribute), true); >> >> >> >> That seems to be ridiculously convoluted and fragile. Isn't there a >> >> better way? >> >> >> >> >> >> >> >> >> > >> > >> > >> > -- >> > Jono >> > >> > > >> > >> >> >> >> -- >> Truth, >> James >> >> > > > > -- > Jono > > > > --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Castle Project Users" group. To post to this group, send email to [email protected] To unsubscribe from this group, send email to [email protected] For more options, visit this group at http://groups.google.com/group/castle-project-users?hl=en -~----------~----~----~----~------~----~------~--~---
