CSLA.NET 6.0.0
CSLA .NET is a software development framework that helps you build a reusable, maintainable object-oriented business layer for your app.
BusinessRuleCases.cs
Go to the documentation of this file.
1using System.Threading.Tasks;
2using Csla.Rules;
3
5{
6 public class ExecuteWithoutAdd
8 {
9 protected override void Execute(IRuleContext context)
10 {
11 // The parameter should have an error
12 // because there are no Add...() calls.
13 }
14 }
15
16 public class ExecuteWithAdd
18 {
19 protected override void Execute(IRuleContext context)
20 {
21 context.AddDirtyProperty(null);
22 }
23 }
24
27 {
28 protected override void Execute(IRuleContext context)
29 {
30 // This shouldn't cause an exception.
31 var c = nameof(context);
32 context.AddDirtyProperty(null);
33 }
34 }
35
36 // Don't lose this comment.
39 {
40 // Or this one either.
41 protected override async void Execute(IRuleContext context)
42 {
43 context.AddDirtyProperty(null);
44 // This method should have an error
45 // because we are not inheriting from BusinessRuleAsync.
46 await DummyAsync();
47 context.Complete();
48 }
49
50 private static Task DummyAsync() => Task.CompletedTask;
51 }
52
55 {
56 protected override async Task ExecuteAsync(IRuleContext context)
57 {
58 context.AddDirtyProperty(null);
59 await DummyAsync();
60 }
61
62 private static Task DummyAsync() => Task.CompletedTask;
63 }
64
65 public class CallingComplete
67 {
68 protected override Task ExecuteAsync(IRuleContext context)
69 {
70 // This method should have an error
71 // because we call Complete().
72 #region keep this
73 context.Complete();
74 #endregion
75 context.AddDirtyProperty(null);
76 context.Complete(); context.Complete();
77 // Keep these comments!
78 context.Complete(); /* And this one */
79
80 context.Complete();
81 return Task.CompletedTask;
82 }
83 }
84
87 {
88 protected override Task ExecuteAsync(IRuleContext context)
89 {
90 // This shouldn't cause an exception.
91 var c = nameof(context);
92 context.AddDirtyProperty(null);
93 // This method should have an error
94 // because we call Complete().
95 context.Complete();
96 return Task.CompletedTask;
97 }
98 }
99}
override async Task ExecuteAsync(IRuleContext context)
Business or validation rule implementation.
override async void Execute(IRuleContext context)
Business or validation rule implementation.
override Task ExecuteAsync(IRuleContext context)
Business or validation rule implementation.
override Task ExecuteAsync(IRuleContext context)
Business or validation rule implementation.
override void Execute(IRuleContext context)
Business or validation rule implementation.
override void Execute(IRuleContext context)
Business or validation rule implementation.
override void Execute(IRuleContext context)
Business or validation rule implementation.
Base class used to create async business and validation rules.
Base class used to create business and validation rules.
Definition: BusinessRule.cs:15
Context information provided to a business rule when it is invoked.
Definition: IRuleContext.cs:22
void Complete()
Indicates that the rule processing is complete, so CSLA .NET will process the Results list.
void AddDirtyProperty(Csla.Core.IPropertyInfo property)
Adds a property name as a dirty field (changed value).