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.
PropertyRule.cs
Go to the documentation of this file.
1//-----------------------------------------------------------------------
2// <copyright file="PropertyRule.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 property level rule</summary>
7//-----------------------------------------------------------------------
8using System;
9using Csla.Core;
10
11namespace Csla.Rules
12{
16 public abstract class PropertyRule : BusinessRule
17 {
21 public string MessageText
22 {
23 get { return MessageDelegate.Invoke(); }
24 set { MessageDelegate = () => value; }
25 }
26
31 public Func<string> MessageDelegate { get; set; }
32
39 protected bool HasMessageDelegate
40 {
41 get { return MessageDelegate != null; }
42 }
43
48 protected virtual string GetMessage()
49 {
50 return MessageText;
51 }
52
56 protected PropertyRule()
57 : base()
58 {
60 CanRunOnServer = true;
61 CanRunInCheckRules = true;
62 }
63
68 protected PropertyRule(IPropertyInfo propertyInfo) : base(propertyInfo)
69 {
71 CanRunOnServer = true;
72 CanRunInCheckRules = true;
73 }
74
82 {
83 get { return (RunMode & RunModes.DenyAsAffectedProperty) == 0; }
84 set
85 {
86 if (value && !CanRunAsAffectedProperty)
87 {
88 RunMode = RunMode ^ RunModes.DenyAsAffectedProperty;
89 }
90 else if (!value && CanRunAsAffectedProperty)
91 {
92 RunMode = RunMode | RunModes.DenyAsAffectedProperty;
93 }
94 }
95 }
96
103 public bool CanRunOnServer
104 {
105 get { return (RunMode & RunModes.DenyOnServerSidePortal) == 0; }
106 set
107 {
108 if (value && !CanRunOnServer)
109 {
110 RunMode = RunMode ^ RunModes.DenyOnServerSidePortal;
111 }
112 else if (!value && CanRunOnServer)
113 {
114 RunMode = RunMode | RunModes.DenyOnServerSidePortal;
115 }
116 }
117 }
118
126 {
127 get { return (RunMode & RunModes.DenyCheckRules) == 0; }
128 set
129 {
130 if (value && !CanRunInCheckRules)
131 {
132 RunMode = RunMode ^ RunModes.DenyCheckRules;
133 }
134 else if (!value && CanRunInCheckRules)
135 {
136 RunMode = RunMode | RunModes.DenyCheckRules;
137 }
138 }
139 }
140 }
141}
RunModes RunMode
Gets or sets the run in context.
Base class used to create business and validation rules.
Definition: BusinessRule.cs:15
Base class for a property rule
Definition: PropertyRule.cs:17
bool CanRunAsAffectedProperty
Gets or sets a value indicating whether this instance can run as affected property.
Definition: PropertyRule.cs:82
PropertyRule()
Initializes a new instance of the PropertyRule class.
Definition: PropertyRule.cs:56
Func< string > MessageDelegate
Gets or sets the error message function for this rule.
Definition: PropertyRule.cs:31
bool CanRunInCheckRules
Gets or sets a value indicating whether this instance can run when CheckRules is called on BO.
PropertyRule(IPropertyInfo propertyInfo)
Initializes a new instance of the PropertyRule class.
Definition: PropertyRule.cs:68
bool CanRunOnServer
Gets or sets a value indicating whether this instance can run in logical serverside data portal.
bool HasMessageDelegate
Gets a value indicating whether this instance has message delegate.
Definition: PropertyRule.cs:40
string MessageText
Gets or sets the error message (constant).
Definition: PropertyRule.cs:22
virtual string GetMessage()
Gets the error message text.
Definition: PropertyRule.cs:48
Maintains metadata about a property.
RunModes
Flags enum to define when rule is allowed or denied to run