MarimerLLC / cslaforum

Discussion forum for CSLA .NET
https://cslanet.com
Other
31 stars 6 forks source link

Execute Rules in Children #889

Open CrossSlide opened 4 years ago

CrossSlide commented 4 years ago

Is there a way to CheckRules on All child BusinessObjects? I have some child rules that look to a parent value. If that parent value changes I need to execute the child rules. An OnParentChanged() event would work. Thanks

CSLA version: 4.6 OS: Windows Platform: WPF

jonnybee commented 4 years ago

You must handle this in the parent object to call/execute rules on the cild items when the "parent" property has changed. F.ex override CheckPropertyRules

[EditorBrowsable(EditorBrowsableState.Advanced)]
protected virtual void CheckPropertyRules(IPropertyInfo property)
{
  var propertyNames = BusinessRules.CheckRules(property);
  if (ApplicationContext.PropertyChangedMode == ApplicationContext.PropertyChangedModes.Windows)
    OnPropertyChanged(property);
  else
    foreach (var name in propertyNames)
      OnPropertyChanged(name);
}

propertyNames will return all changed/affected properties in this validation.

CrossSlide commented 4 years ago

Thank you @jonnybee for the help!