CSLA.NET 5.4.2
CSLA .NET is a software development framework that helps you build a reusable, maintainable object-oriented business layer for your app.
BusinessRuleBase.cs
Go to the documentation of this file.
1//-----------------------------------------------------------------------
2// <copyright file="BusinessRuleBase.cs" company="Marimer LLC">
3// Copyright (c) Marimer LLC. All rights reserved.
4// Website: https://cslanet.com
5// </copyright>
6// <summary>Base class used to create business and validation</summary>
7//-----------------------------------------------------------------------
8using System;
9using System.Collections.Generic;
10using Csla.Properties;
11
12namespace Csla.Rules
13{
18 public abstract class BusinessRuleBase : IBusinessRuleBase
19 {
20 private Csla.Core.IPropertyInfo _primaryProperty;
21 private RunModes _runMode;
22 private bool _provideTargetWhenAsync;
23 private int _priority;
24 private RuleUri _ruleUri;
25
31 protected bool PropertiesLocked { get; set; }
32
37 {
38 get { return _primaryProperty; }
39 set
40 {
41 CanWriteProperty("PrimaryProperty");
42 _primaryProperty = value;
43 this.RuleUri = new RuleUri(this, value);
44 if (_primaryProperty != null)
45 AffectedProperties.Add(_primaryProperty);
46 }
47 }
48
54 public List<Csla.Core.IPropertyInfo> AffectedProperties { get; private set; }
55
60 public List<Csla.Core.IPropertyInfo> InputProperties { get; protected set; }
61
66 public abstract bool IsAsync { get; protected set; }
67
74 {
75 get { return _provideTargetWhenAsync; }
76 protected set
77 {
78 CanWriteProperty("ProvideTargetWhenAsync");
79 _provideTargetWhenAsync = value;
80 }
81 }
82
88 public string RuleName { get { return this.RuleUri.ToString(); } }
89
93 protected RuleUri RuleUri
94 {
95 get { return _ruleUri; }
96 set
97 {
98 CanWriteProperty("RuleUri");
99 _ruleUri = value;
100 }
101 }
102
106 public int Priority
107 {
108 get { return _priority; }
109 set
110 {
111 CanWriteProperty("Priority");
112 _priority = value;
113 }
114 }
115
121 {
122 get { return _runMode; }
123 set
124 {
125 CanWriteProperty("RunMode");
126 _runMode = value;
127 }
128 }
129
134 protected void CanWriteProperty(string argument)
135 {
136 if (PropertiesLocked) throw
137 new ArgumentException(string.Format("{0} ({1})", Resources.PropertySetNotAllowed, argument), argument);
138 }
139
145 protected BusinessRuleBase(Csla.Core.IPropertyInfo primaryProperty)
146 {
147 AffectedProperties = new List<Core.IPropertyInfo>();
148 InputProperties = new List<Core.IPropertyInfo>();
149 PrimaryProperty = primaryProperty;
150 this.RuleUri = new RuleUri(this, primaryProperty);
151 RunMode = RunModes.Default;
152 }
153
172 protected void LoadProperty(object obj, Csla.Core.IPropertyInfo propertyInfo, object newValue)
173 {
174 if (obj is Core.IManageProperties target)
175 target.LoadProperty(propertyInfo, newValue);
176 else
177 throw new ArgumentException(Resources.IManagePropertiesRequiredException);
178 }
179
191 protected object ReadProperty(object obj, Csla.Core.IPropertyInfo propertyInfo)
192 {
193 if (obj is Core.IManageProperties target)
194 return target.ReadProperty(propertyInfo);
195 else
196 throw new ArgumentException(Resources.IManagePropertiesRequiredException);
197 }
198 }
199}
A strongly-typed resource class, for looking up localized strings, etc.
static string IManagePropertiesRequiredException
Looks up a localized string similar to Target object must implement IManageProperties.
static string PropertySetNotAllowed
Looks up a localized string similar to Property set not allowed.
Base class used to create business and validation rules.
void CanWriteProperty(string argument)
Allows or blocks changing a property value.
virtual Csla.Core.IPropertyInfo PrimaryProperty
Gets or sets the primary property affected by this rule.
object ReadProperty(object obj, Csla.Core.IPropertyInfo propertyInfo)
Reads a property's field value.
void LoadProperty(object obj, Csla.Core.IPropertyInfo propertyInfo, object newValue)
Loads a property's managed field with the supplied value calling PropertyHasChanged if the value does...
bool ProvideTargetWhenAsync
Gets a value indicating that the Target property should be set even for an async rule (note that usin...
BusinessRuleBase(Csla.Core.IPropertyInfo primaryProperty)
Creates an instance of the rule that applies to a specfic property.
string RuleName
Gets a unique rule:// URI for the specific instance of the rule within the context of the business ob...
int Priority
Gets the rule priority.
RunModes RunMode
Gets or sets the run in context.
List< Csla.Core.IPropertyInfo > InputProperties
Gets a list of secondary property values to be supplied to the rule when it is executed.
bool PropertiesLocked
Gets or sets a value indicating whether property values should be locked because an async operation i...
List< Csla.Core.IPropertyInfo > AffectedProperties
Gets a list of properties affected by this rule.
abstract bool IsAsync
Gets a value indicating whether the rule will run on a background thread.
RuleUri RuleUri
Sets or gets the rule:// URI object for this rule.
Parses a rule:// URI to provide easy access to the parts of the URI.
Definition: RuleUri.cs:19
override string ToString()
Gets a string representation of the rule URI.
Definition: RuleUri.cs:103
Maintains metadata about a property.
Interface defining a business/validation rule implementation.
RunModes
Flags enum to define when rule is allowed or denied to run