New Posts New Posts RSS Feed: Get/Set Interceptors
  FAQ FAQ  Forum Search   Calendar   Register Register  Login Login

Get/Set Interceptors

 Post Reply Post Reply
Author
ken.nelson View Drop Down
Groupie
Groupie


Joined: 03-Mar-2009
Location: Ann Arbor, MI
Posts: 54
Post Options Post Options   Quote ken.nelson Quote  Post ReplyReply Direct Link To This Post Topic: Get/Set Interceptors
    Posted: 10-Mar-2009 at 10:36am
Excellent.  Thanks!
Back to Top
kimj View Drop Down
IdeaBlade
IdeaBlade
Avatar

Joined: 09-May-2007
Posts: 1391
Post Options Post Options   Quote kimj Quote  Post ReplyReply Direct Link To This Post Posted: 10-Mar-2009 at 9:48am

Property interceptors in a nested public class will still automatically be discovered and applied to properties in the parent class, so you can do something like the following to lessen Intellisense clutter:

public partial class Employee {
 
   public class NestedPropertyInterceptors {
       [BeforeGet(EntityPropertyNames.LastName)]
       public static void BeforeGetLastName(IPropertyInterceptorArgs args) {
          var emp = args.Instance as Employee;
          Console.Writeline("emp:BeforeGetLastName");
       }
    }
}
 
You can also define interception methods in a separate class, being sure to provide the TargetType of the interceptor, and then call the DiscoverInterceptorsFromAttributes method of the PropertyInterceptorManager to force discovery, like this:
 
PropertyInterceptorManager.CurrentInstance.DiscoverInterceptorsFromAttributes(
          typeof(EmployeeInterceptorExtensions));
 
    public class EmployeeInterceptorExtensions {
 
        [BeforeSet( Employee.EntityPropertyNames.Country, TargetType=typeof(Employee))]
        public static void LowercaseCountry(IPropertyInterceptorArgs<Employee, String> args) {
           var country = args.Value;
           if (!String.IsNullOrEmpty(country)) {
             args.Value = country.ToLower();
           }
        }
    }
Back to Top
ken.nelson View Drop Down
Groupie
Groupie


Joined: 03-Mar-2009
Location: Ann Arbor, MI
Posts: 54
Post Options Post Options   Quote ken.nelson Quote  Post ReplyReply Direct Link To This Post Posted: 10-Mar-2009 at 7:59am
Thanks for the info.
 
I have one follow on question regarding Property Interceptors.  It appears that any method defined as a Property Interceptor must have public scope.  When I tried private and internal the method never executes.  While it's not a huge problem to have these methods be public, it really dirties up Intellisense.
 
I've tried using the System.ComponentModel attribute: [EditorBrowsable(EditorBrowsableState.Never)] but it still does not hide the method from displaying in Intellisense.
 
The only other 'solution' I could find to the problem was to prefix all of my Property Interceptors with an underline "_", to force them to move out of the way in Intellisense, but this is more of a hack than a real solution, and they're still visible in Intellisense, they're just not mixed in with real properties and methods.
 
Do you have a workaround for this?
 
Thanks,
Ken
Back to Top
kimj View Drop Down
IdeaBlade
IdeaBlade
Avatar

Joined: 09-May-2007
Posts: 1391
Post Options Post Options   Quote kimj Quote  Post ReplyReply Direct Link To This Post Posted: 05-Mar-2009 at 1:59pm
Ken,
 
You're not doing anything wrong.  We didn't get the documentation completely synchronized with the current functionality, and as you've found still have some old information.  We'll fix this ASAP.
 
In version 4.3.0 the get/set interceptors are always available and not controlled via the Object Mapper.  See the new chapter on Property Interceptors in the Dev Guide for information on how to use them.
Back to Top
ken.nelson View Drop Down
Groupie
Groupie


Joined: 03-Mar-2009
Location: Ann Arbor, MI
Posts: 54
Post Options Post Options   Quote ken.nelson Quote  Post ReplyReply Direct Link To This Post Posted: 05-Mar-2009 at 12:37pm
Hi, I'm using DevForceEF version 4.3.0 and am a little confused about Get/Set interceptors.  Mostly because I can't seem to find them anywhere.  In previous versions of DevForceEF, in the Object Mapper I was able to choose from Get/Set Interceptor modes, and it's still in the current documentation that this is still supported (around page 119 of the Developers Guide), but the options simply aren't there for me.  Any idea what I'm doing wrong?


Edited by ken.nelson - 05-Mar-2009 at 12:38pm
Back to Top
 Post Reply Post Reply

Forum Jump Forum Permissions View Drop Down