2using System.Collections.Generic;
6using Microsoft.AspNetCore.Components.Forms;
13 public static class EditContextCslaExtensions
19 public static EditContext AddCslaValidation(
this EditContext editContext)
21 if (editContext ==
null)
23 throw new ArgumentNullException(nameof(editContext));
26 var messages =
new ValidationMessageStore(editContext);
29 editContext.OnValidationRequested +=
30 (sender, eventArgs) => ValidateModel((EditContext)sender, messages);
33 editContext.OnFieldChanged +=
34 (sender, eventArgs) => ValidateField(editContext, messages, eventArgs.FieldIdentifier);
45 private static void ValidateModel(EditContext editContext, ValidationMessageStore messages)
53 if (editContext.Model ==
null)
55 throw new ArgumentNullException(nameof(editContext.Model));
59 throw new ArgumentException(
68 foreach (var brokenRule
in brokenRuleNode.BrokenRules)
72 messages.Add(
new FieldIdentifier(brokenRuleNode.Object, brokenRule.Property), brokenRule.Description);
77 editContext.NotifyValidationStateChanged();
87 private static void ValidateField(EditContext editContext, ValidationMessageStore messages, in FieldIdentifier fieldIdentifier)
97 throw new ArgumentException(
99 nameof(fieldIdentifier.Model), nameof(
ICheckRules)));
103 messages.Clear(fieldIdentifier);
108 if (fieldIdentifier.FieldName.Equals(brokenRule.
Property))
111 messages.Add(fieldIdentifier, brokenRule.
Description);
118 editContext.NotifyValidationStateChanged();
A strongly-typed resource class, for looking up localized strings, etc.
static string InterfaceNotImplementedException
Looks up a localized string similar to {0} does not implement required interface {1}.
Stores details about a specific broken business rule.
string Property
Provides access to the property affected by the broken rule.
string Description
Provides access to the description of the broken rule.
RuleSeverity Severity
Gets the severity of the broken rule.
Tracks the business rules for a business object.
static BrokenRulesTree GetAllBrokenRules(object root)
Gets all nodes in tree that have IsValid = false (and all parents)
Defines the common methods for any business object which exposes means to supress and check business ...
BrokenRulesCollection GetBrokenRules()
Gets the broken rules collection
RuleSeverity
Values for validation rule severities.