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.
PropertyRuleAsync.cs
Go to the documentation of this file.
1//-----------------------------------------------------------------------
2// <copyright file="PropertyRuleAsync.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 PropertyRuleAsync : BusinessRuleAsync
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
57 : base()
58 {
60 CanRunOnServer = true;
61 CanRunInCheckRules = true;
62 }
63
68 protected PropertyRuleAsync(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}
Base class used to create async business and validation rules.
RunModes RunMode
Gets or sets the run in context.
Base class for a property rule
virtual string GetMessage()
Gets the error message text.
Func< string > MessageDelegate
Gets or sets the error message function for this rule.
bool CanRunOnServer
Gets or sets a value indicating whether this instance can run in logical serverside data portal.
PropertyRuleAsync()
Initializes a new instance of the PropertyRule class.
bool CanRunInCheckRules
Gets or sets a value indicating whether this instance can run when CheckRules is called on BO.
string MessageText
Gets or sets the error message (constant).
PropertyRuleAsync(IPropertyInfo propertyInfo)
Initializes a new instance of the PropertyRule class.
bool CanRunAsAffectedProperty
Gets or sets a value indicating whether this instance can run as affected property.
bool HasMessageDelegate
Gets a value indicating whether this instance has message delegate.
Maintains metadata about a property.
RunModes
Flags enum to define when rule is allowed or denied to run