I have found some examples how to create an interceptor, for instance
this http://robtennyson.us/post/2009/08/23/NHibernate-Interceptors.aspx
but what I really want to do is to setup when the interception should
happen kinda like this
public bool ShouldInterceptMethod(Type type, MethodInfo memberInfo)
{ return
(memberInfo.IsGetterOrSetterForPropertyWithAttribute(typeof(SomeAttribute))); }

and then in the interception method i would return the value from the
detailscollection kinda like this

public void Intercept(IInvocation invocation)
   2: {
   3:     TypedPageData invocationTarget = (TypedPageData)
invocation.InvocationTarget;
   4:     string propertyName = invocation.Method.GetPropertyName();
   5:     if (invocation.Method.IsGetter())
   6:     {
   7:         invocation.ReturnValue = invocationTarget[propertyName];
   8:         if ((invocation.ReturnValue == null) &&
(invocation.Method.ReturnType == typeof(bool)))
   9:         {
  10:             invocation.ReturnValue = false;
  11:         }
  12:     }
  13:     else
  14:     {
  15:         invocationTarget.SetValue(propertyName,
invocation.Arguments[0]);
  16:     }
  17: }

any pointers on that?

On Sep 23, 10:48 pm, James Gregory <jagregory....@gmail.com> wrote:
> Do a search for NHibernate IInterceptor, there's a lot of resources out
> there on it.
>
>
>
> On Thu, Sep 23, 2010 at 8:13 PM, marcus <mar...@meridium.se> wrote:
> > I would appreciate any feedback on this question
>
> > On Sep 16, 7:59 pm, marcus <mar...@meridium.se> wrote:
> > > Let me rephrase the question, is it possible to intercept when the
> > > persistence service creates the instance of, in my case ContentItem?
>
> > > The goal with this is to intercept when all auto properties is access
> > > on any class that is a subclass of ContentItem.
> > > My classes looks like this:
>
> > >    public abstract class ContentItem : IContentItem {
> > >         public virtual int? Id { get; set; }
> > >         [ContentDetail]
> > >         public virtual string Name { get; set; }
> > >         [ContentDetail]
> > >         public virtual IDictionary<string, ContentDetail> Details
> > > { get; private set; }
> > >         protected ContentItem() {
> > >             Details = new Dictionary<string, ContentDetail>();
> > >         }
> > >     }
>
> > > and the the subclass
> > > public class Home : ContentItem {
> > >         [SomeAttribute]
> > >         public virtual string Heading { get; set; }
>
> > > }
>
> > > So when Heading property is access I want to intercept and return the
> > > value of Details["Heading"] from the base class.
> > > Is it possible to do so or has it not even with FNH to do?
>
> > > On Sep 16, 12:43 pm, marcus <mar...@meridium.se> wrote:
>
> > > > Is it possible to setup an interceptor that intercepts when accessing
> > > > for example a property or a method on the proxy class? I also use
> > > > structuremap as an IoC.
>
> > --
> > You received this message because you are subscribed to the Google Groups
> > "Fluent NHibernate" group.
> > To post to this group, send email to fluent-nhibern...@googlegroups.com.
> > To unsubscribe from this group, send email to
> > fluent-nhibernate+unsubscr...@googlegroups.com<fluent-nhibernate%2Bunsubscr 
> > i...@googlegroups.com>
> > .
> > For more options, visit this group at
> >http://groups.google.com/group/fluent-nhibernate?hl=en.

-- 
You received this message because you are subscribed to the Google Groups 
"Fluent NHibernate" group.
To post to this group, send email to fluent-nhibern...@googlegroups.com.
To unsubscribe from this group, send email to 
fluent-nhibernate+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/fluent-nhibernate?hl=en.

Reply via email to