-
Notifications
You must be signed in to change notification settings - Fork 0
/
ValidatedItemRule.cs
98 lines (81 loc) · 2.77 KB
/
ValidatedItemRule.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
using FFP.CoreUtilities;
namespace Validations
{
public class ValidatedItemRule : IRule
{
public const string STR_EMPTY = "(Empty)";
protected ValidatedItemRule(string v)
{
}
public ValidatedItemRule(string Validation, string Description)
{
RuleName = Validation;
this.Description = Description;
this.Severity = ValidationSeverity.Critical;
}
public ValidatedItemRule(string Validation, string Description, ValidationDelegate<IValidatedItem> handler)
{
RuleName = Validation;
this.Description = Description;
ValidationHandler = handler;
}
bool IRule.IsBroken(object itm)
{
if (ValidationHandler == null)
{
return false;
}
else
{
if (itm is IValidatedItem)
{
return ValidationHandler.Invoke(this, (IValidatedItem)itm);
}
else
{
return ValidationHandler.Invoke(this, new ValidateItemWrapper(itm));
}
}
}
private ValidationDelegate<IValidatedItem> ValidationHandler { get; set; }
public ValidationSeverity Severity { get; set; } = ValidationSeverity.Critical;
public string RuleName { get; set; } = "";
private string _description1;
public string Description
{
get
{
return CSLA.Resources.Strings.GetResourceString(RuleName, _description1);
}
set
{
_description1 = value;
}
}
string IRuleDescription.RuleName { get => throw new System.NotImplementedException(); set => throw new System.NotImplementedException(); }
string IRuleDescription.Description { get => throw new System.NotImplementedException(); set => throw new System.NotImplementedException(); }
ValidationSeverity IRuleDescription.Severity { get => throw new System.NotImplementedException(); set => throw new System.NotImplementedException(); }
public override bool Equals(object obj)
{
if (obj == null)
return false;
if (obj is IRule)
{
IRule ValidationToCompare = (IRule)obj;
if (ValidationToCompare.RuleName.CompareAbsolute(RuleName))
{
return true;
}
}
return false;
}
public override string ToString()
{
return Description;
}
public override int GetHashCode()
{
return (RuleName).GetHashCode();
}
}
}