-
Notifications
You must be signed in to change notification settings - Fork 0
/
ValidationManagerFactory.cs
93 lines (78 loc) · 3.7 KB
/
ValidationManagerFactory.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
using System;
using System.Collections.Generic;
using ValidationFramework.Reflection;
namespace ValidationFramework
{
public static class ValidationManagerFactory
{
private static Dictionary<InfoDescriptor, List<Rule>> GetDictionary<TInfoDescriptor>(AutoKeyDictionary<string, TInfoDescriptor> properties, string ruleSet) where TInfoDescriptor : InfoDescriptor
{
var dictionary = new Dictionary<InfoDescriptor, List<Rule>>();
foreach (var descriptor in properties)
{
var rules = new List<Rule>();
foreach (var rule in descriptor.Rules.GetRulesForRuleSet(ruleSet))
{
rules.Add(rule);
}
dictionary.Add(descriptor, rules);
}
return dictionary;
}
public static MemberValidationManager GetPropertyValidationManager(object target)
{
return GetPropertyValidationManager(target, null);
}
public static MemberValidationManager GetPropertyValidationManager(object target, string ruleSet)
{
var typeDescriptor = TypeCache.GetType(target.GetType());
return new MemberValidationManager(GetDictionary(typeDescriptor.Properties, ruleSet)) { Target = target };
}
public static MemberValidationManager GetPropertyValidationManager<T>()
{
return GetPropertyValidationManager<T>(null);
}
public static MemberValidationManager GetPropertyValidationManager<T>(string ruleSet)
{
var typeDescriptor = TypeCache.GetType(typeof(T));
return new MemberValidationManager(GetDictionary(typeDescriptor.Properties, ruleSet)) { TargetType = typeof(T) };
}
public static MemberValidationManager GetPropertyValidationManager(Type runtimeType)
{
return GetPropertyValidationManager(runtimeType, null);
}
public static MemberValidationManager GetPropertyValidationManager(Type runtimeType, string ruleSet)
{
var typeDescriptor = TypeCache.GetType(runtimeType);
return new MemberValidationManager(GetDictionary(typeDescriptor.Properties, ruleSet)) { TargetType = runtimeType };
}
public static MemberValidationManager GetFieldValidationManager<T>()
{
return GetFieldValidationManager<T>(null);
}
public static MemberValidationManager GetFieldValidationManager<T>(string ruleSet)
{
var typeDescriptor = TypeCache.GetType(typeof(T));
return new MemberValidationManager(GetDictionary(typeDescriptor.Fields, ruleSet)) { TargetType = typeof(T) };
}
public static MemberValidationManager GetFieldValidationManager(object target)
{
return GetFieldValidationManager(target, null);
}
public static MemberValidationManager GetFieldValidationManager(object target, string ruleSet)
{
var typeDescriptor = TypeCache.GetType(target.GetType());
return new MemberValidationManager(GetDictionary(typeDescriptor.Fields, ruleSet)) { Target = target };
}
public static MemberValidationManager GetFieldValidationManager(Type runtimeType)
{
return GetFieldValidationManager(runtimeType, null);
}
public static MemberValidationManager GetFieldValidationManager(Type runtimeType, string ruleSet)
{
var typeDescriptor = TypeCache.GetType(runtimeType);
return new MemberValidationManager(GetDictionary(typeDescriptor.Fields, ruleSet)) { TargetType = runtimeType };
}
}
}