Print Page | Close Window

Interceptors not fired for changes made in AfterSet interceptor

Printed From: IdeaBlade
Category: DevForce
Forum Name: DevForce 2009
Forum Discription: For .NET 3.5
URL: http://www.ideablade.com/forum/forum_posts.asp?TID=1459
Printed Date: 20-Sep-2025 at 9:48am


Topic: Interceptors not fired for changes made in AfterSet interceptor
Posted By: Sinnema
Subject: Interceptors not fired for changes made in AfterSet interceptor
Date Posted: 09-Sep-2009 at 6:03am
Hi,
 
We've created the following, very simple, code to reset booleans in other rows of a Navigation Property. The functionality should be like this:
- We have several Addresses but only 1 can be the Postal Address
- Each Address has an IsPostal boolean which tells if this Address is the Postal Address
- When a IsPostal for an Address is set to true, all others should be disabled automatically
 
The code below works fine. The booleans for the other items are realy set to false but the Interceptors which are coupled to these properties are not fired. This behavior prevent our mask to be updated with the new values.
 
Regards,
Paul Sinnema
Diartis AG
 
  [AfterSet(EntityPropertyNames.IsPostal)]
  public void AfterSetIsPostal(PropertyInterceptorArgs<Address, Boolean> args)
  {
   ResetIsPostal(args);
  }
 
  private void ResetIsPostal(PropertyInterceptorArgs<Address, Boolean> args)
  {
   if (args.Value)
   {
    foreach (var item in this.Contact.AddressList.Where(address => !address.Equals(this)))
    {
     if (item.IsPostal)
     {
      item.IsPostal = false;
     }
    }
   }
  }



Replies:
Posted By: Sinnema
Date Posted: 09-Sep-2009 at 6:48am
Hi,
 
We've solved it as shown below. Is that really the way to solve this? I would hate it to have to write that much code for each set of the same property in other Items. We noticed that when we set another property (i.e. not the property that is changing now) then the value is set correctly and it's interceptor is fired too.
 
Regards,
Paul Sinnema.
Diartis AG
 
  [AfterSet(EntityPropertyNames.IsPostal)]
  public void AfterSetIsPostal(PropertyInterceptorArgs<Address, Boolean> args)
  {
   ResetIsPostal(args);
  }
  private void ResetIsPostal(PropertyInterceptorArgs<Address, Boolean> args)
  {
   if (args.Value)
   {
    foreach (var item in this.Contact.AddressList.Where(address => !address.Equals(this)))
    {
     if (item.IsPostal)
     {
      item.IsPostal = false;
      FireIsPostalSetters(item, false);
     }
    }
   }
  }
  private void FireIsPostalSetters(Address address, bool value)
  {
   var actions = Address.IsPostalEntityProperty.SetterInterceptor.GetActions();
   var args = new DataEntityPropertySetInterceptorArgs<Address, Boolean>(Address.IsPostalEntityProperty, address, null);
   args.Value = value;
   foreach (var item in actions)
   {
    item.Action(args);
   }
  }



Print Page | Close Window