From 8ec41f952b8aceb1035f404aa85461390a21b4bb Mon Sep 17 00:00:00 2001 From: Rockford Lhotka Date: Wed, 13 Mar 2024 15:11:37 -0700 Subject: [PATCH] #3721 Add CascadeIfDirty property to make optimization opt-in --- Source/Csla/Rules/BusinessRuleBase.cs | 6 ++++++ Source/Csla/Rules/BusinessRules.cs | 14 +++++++------- Source/Csla/Rules/IBusinessRule.cs | 5 +++++ 3 files changed, 18 insertions(+), 7 deletions(-) diff --git a/Source/Csla/Rules/BusinessRuleBase.cs b/Source/Csla/Rules/BusinessRuleBase.cs index dc9aceaca6..746fb1e29d 100644 --- a/Source/Csla/Rules/BusinessRuleBase.cs +++ b/Source/Csla/Rules/BusinessRuleBase.cs @@ -23,6 +23,12 @@ public abstract class BusinessRuleBase : IBusinessRuleBase private int _priority; private RuleUri _ruleUri; + /// + /// If true, rule will only cascade if the primary property + /// is dirty. + /// + public bool CascadeIfDirty { get; protected set; } + /// /// Gets or sets a value indicating whether /// property values should be locked because diff --git a/Source/Csla/Rules/BusinessRules.cs b/Source/Csla/Rules/BusinessRules.cs index b2aafaa472..01f1ca7c05 100644 --- a/Source/Csla/Rules/BusinessRules.cs +++ b/Source/Csla/Rules/BusinessRules.cs @@ -675,21 +675,21 @@ orderby r.Priority propertiesToRun.Add(p); } - // gets a list of "affected" properties by adding + // gets a list rules of of "affected" properties by adding // PrimaryProperty where property is in InputProperties - var input = from r in TypeRules.Rules + var inputRules = from r in TypeRules.Rules where !ReferenceEquals(r.PrimaryProperty, property) && r.PrimaryProperty != null && r.InputProperties != null && r.InputProperties.Contains(property) - select r.PrimaryProperty; + select r; var dirtyProperties = primaryResult.DirtyProperties; - input = from r in input - where dirtyProperties.Contains(r.Name) - select r; + var inputProperties = from r in inputRules + where !r.CascadeIfDirty || dirtyProperties.Contains(r.PrimaryProperty.Name) + select r.PrimaryProperty; - foreach (var p in input) + foreach (var p in inputProperties) { if (!ReferenceEquals(property, p)) propertiesToRun.Add(p); diff --git a/Source/Csla/Rules/IBusinessRule.cs b/Source/Csla/Rules/IBusinessRule.cs index bded0c2d47..45e6c1f3df 100644 --- a/Source/Csla/Rules/IBusinessRule.cs +++ b/Source/Csla/Rules/IBusinessRule.cs @@ -41,6 +41,11 @@ public enum RunModes /// public interface IBusinessRuleBase { + /// + /// If true, rule will only cascade if the primary property + /// is dirty. + /// + bool CascadeIfDirty { get; } /// /// Gets a list of secondary property values to be supplied to the /// rule when it is executed.