Skip to content

Commit

Permalink
Merge pull request #3732 from rockfordlhotka/3721-rules
Browse files Browse the repository at this point in the history
Add CascadeIfDirty property to make optimization opt-in
  • Loading branch information
rockfordlhotka authored Mar 14, 2024
2 parents 77d5d51 + 8ec41f9 commit 368b8a3
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 7 deletions.
6 changes: 6 additions & 0 deletions Source/Csla/Rules/BusinessRuleBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,12 @@ public abstract class BusinessRuleBase : IBusinessRuleBase
private int _priority;
private RuleUri _ruleUri;

/// <summary>
/// If true, rule will only cascade if the primary property
/// is dirty.
/// </summary>
public bool CascadeIfDirty { get; protected set; }

/// <summary>
/// Gets or sets a value indicating whether
/// property values should be locked because
Expand Down
14 changes: 7 additions & 7 deletions Source/Csla/Rules/BusinessRules.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
5 changes: 5 additions & 0 deletions Source/Csla/Rules/IBusinessRule.cs
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,11 @@ public enum RunModes
/// </summary>
public interface IBusinessRuleBase
{
/// <summary>
/// If true, rule will only cascade if the primary property
/// is dirty.
/// </summary>
bool CascadeIfDirty { get; }
/// <summary>
/// Gets a list of secondary property values to be supplied to the
/// rule when it is executed.
Expand Down

0 comments on commit 368b8a3

Please sign in to comment.