Nhibernate is an ORM framework, you are looking for AOP. You can use
castle dynamic proxy, the same nhibernate uses for lazy loading. There
are tons of examples of how to hook to nhibernate a factory for the
instances. You can search nh + inotifypropertychange. Alternatively
you can use static aop, i.e. POSTSHARP.

2010/9/24, marcus <[email protected]>:
> 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.
>
> 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.Details[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: }
>
> How can I achive this with nhibernate?
>
> --
> You received this message because you are subscribed to the Google Groups
> "nhusers" 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/nhusers?hl=en.
>
>

-- 
Enviado desde mi dispositivo móvil

-- 
You received this message because you are subscribed to the Google Groups 
"nhusers" 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/nhusers?hl=en.

Reply via email to