@@ -10,6 +10,25 @@ namespace ServiceStack
10
10
[ Obsolete ( "Use TypeProperties<T>.Instance" ) ]
11
11
public static class TypeReflector < T > { }
12
12
13
+ public class TypePropertyInfo
14
+ {
15
+ public TypePropertyInfo (
16
+ PropertyInfo propertyInfo ,
17
+ Func < object , object > publicGetter ,
18
+ Action < object , object > publicSetter )
19
+ {
20
+ PropertyInfo = propertyInfo ;
21
+ PublicGetter = publicGetter ;
22
+ PublicSetter = publicSetter ;
23
+ }
24
+
25
+ public PropertyInfo PropertyInfo { get ; }
26
+
27
+ public Func < object , object > PublicGetter { get ; }
28
+
29
+ public Action < object , object > PublicSetter { get ; }
30
+ }
31
+
13
32
public class TypeProperties < T > : TypeProperties
14
33
{
15
34
public static readonly TypeProperties < T > Instance = new TypeProperties < T > ( ) ;
@@ -22,9 +41,11 @@ static TypeProperties()
22
41
{
23
42
try
24
43
{
25
- Instance . PublicGetters [ pi . Name ] = pi . GetValueGetter ( typeof ( T ) ) ;
26
- Instance . PublicSetters [ pi . Name ] = pi . GetValueSetter ( typeof ( T ) ) ;
27
- Instance . PublicProperties [ pi . Name ] = pi ;
44
+ Instance . PropertyMap [ pi . Name ] = new TypePropertyInfo (
45
+ pi ,
46
+ pi . GetValueGetter ( typeof ( T ) ) ,
47
+ pi . GetValueSetter ( typeof ( T ) )
48
+ ) ;
28
49
}
29
50
catch ( Exception ex )
30
51
{
@@ -65,14 +86,8 @@ public static TypeProperties Get(Type type)
65
86
66
87
public Type Type { get ; protected set ; }
67
88
68
- public readonly Dictionary < string , Func < object , object > > PublicGetters =
69
- new Dictionary < string , Func < object , object > > ( PclExport . Instance . InvariantComparerIgnoreCase ) ;
70
-
71
- public readonly Dictionary < string , Action < object , object > > PublicSetters =
72
- new Dictionary < string , Action < object , object > > ( PclExport . Instance . InvariantComparerIgnoreCase ) ;
73
-
74
- public readonly Dictionary < string , PropertyInfo > PublicProperties =
75
- new Dictionary < string , PropertyInfo > ( PclExport . Instance . InvariantComparerIgnoreCase ) ;
89
+ public readonly Dictionary < string , TypePropertyInfo > PropertyMap =
90
+ new Dictionary < string , TypePropertyInfo > ( PclExport . Instance . InvariantComparerIgnoreCase ) ;
76
91
77
92
public PropertyInfo [ ] PublicPropertyInfos { get ; protected set ; }
78
93
@@ -86,43 +101,27 @@ public PropertyInfo GetPublicProperty(string name)
86
101
return null ;
87
102
}
88
103
89
- public Func < object , object > GetPublicGetter ( PropertyInfo pi )
90
- {
91
- if ( pi == null )
92
- return null ;
93
-
94
- return PublicGetters . TryGetValue ( pi . Name , out Func < object , object > fn )
95
- ? fn
96
- : pi . GetValueGetter ( ) ;
97
- }
104
+ public Func < object , object > GetPublicGetter ( PropertyInfo pi ) => GetPublicGetter ( pi ? . Name ) ;
98
105
99
106
public Func < object , object > GetPublicGetter ( string name )
100
107
{
101
108
if ( name == null )
102
109
return null ;
103
110
104
- return PublicGetters . TryGetValue ( name , out Func < object , object > fn )
105
- ? fn
111
+ return PropertyMap . TryGetValue ( name , out TypePropertyInfo info )
112
+ ? info . PublicGetter
106
113
: null ;
107
114
}
108
115
109
- public Action < object , object > GetPublicSetter ( PropertyInfo pi )
110
- {
111
- if ( pi == null )
112
- return null ;
113
-
114
- return PublicSetters . TryGetValue ( pi . Name , out Action < object , object > fn )
115
- ? fn
116
- : pi . GetValueSetter ( ) ;
117
- }
116
+ public Action < object , object > GetPublicSetter ( PropertyInfo pi ) => GetPublicSetter ( pi ? . Name ) ;
118
117
119
118
public Action < object , object > GetPublicSetter ( string name )
120
119
{
121
120
if ( name == null )
122
121
return null ;
123
122
124
- return PublicSetters . TryGetValue ( name , out Action < object , object > fn )
125
- ? fn
123
+ return PropertyMap . TryGetValue ( name , out TypePropertyInfo info )
124
+ ? info . PublicSetter
126
125
: null ;
127
126
}
128
127
}
0 commit comments