Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add CascadeIfDirty property to make optimization opt-in #3732

Merged
merged 1 commit into from
Mar 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading