public override IRuleResult Execute(IBase target) { var value = ReadProperty(target, TriggerProperties[0]); bool isError = false; if (value is string s) { isError = string.IsNullOrWhiteSpace(s); } else if (value?.GetType().IsValueType ?? false) { isError = value == Activator.CreateInstance(value.GetType()); } else { isError = value == null; } if (isError) { return(RuleResult.PropertyError(TriggerProperties[0], $"{TriggerProperties[0]} is required.")); } else { return(RuleResult.Empty()); } }
public ValidateObject(IValidateBaseServices <ValidateObject> services) : base(services) { RuleManager.AddRule(t => { t.RuleRunCount++; if (t.Name == "Error") { return(RuleResult.PropertyError(nameof(Name), "Error")); } return(RuleResult.Empty()); }, nameof(Name)); }
public override IRuleResult Execute(T target) { RunCount++; // System.Diagnostics.Debug.WriteLine($"Run Rule {target.FirstName} {target.LastName}"); if (target.FirstName?.StartsWith("Error") ?? false) { return(RuleResult.PropertyError(nameof(IPersonBase.FirstName), target.FirstName)); } target.ShortName = $"{target.FirstName} {target.LastName}"; return(RuleResult.Empty()); }
public override IRuleResult Execute(T target) { // System.Diagnostics.Debug.WriteLine($"Run Rule {target.FirstName} {target.LastName}"); var dd = DisposableDependency ?? throw new ArgumentNullException(nameof(DisposableDependency)); if (target.FirstName?.StartsWith("Error") ?? false) { return(RuleResult.PropertyError(nameof(IPersonBase.FirstName), target.FirstName)); } target.ShortName = $"{target.FirstName} {target.LastName}"; return(RuleResult.Empty()); }
public override async Task <IRuleResult> Execute(T target, CancellationToken token) { RunCount++; await Task.Delay(10, token); // System.Diagnostics.Debug.WriteLine($"ShortNameAsyncRule {target.FirstName} {target.LastName}"); if (target.FirstName?.StartsWith("Error") ?? false) { return(RuleResult.PropertyError(nameof(IPersonBase.FirstName), target.FirstName)); } target.ShortName = $"{target.FirstName} {target.LastName}"; return(RuleResult.Empty()); }
public override IRuleResult Execute(IShortNameRuleTarget target) { if (string.IsNullOrWhiteSpace(target.FirstName)) { return((IRuleResult)RuleResult.PropertyError(nameof(IShortNameRuleTarget.FirstName), "FirstName is required")); } if (string.IsNullOrWhiteSpace(target.LastName)) { return((IRuleResult)RuleResult.PropertyError(nameof(IShortNameRuleTarget.LastName), "LastName is required")); } target.ShortName = $"{target.FirstName} {target.LastName}"; // No support for overloaded methods target.ToUpperCase(); return((IRuleResult)RuleResult.Empty()); }