@@ -45,7 +45,7 @@ public static class Validating
45
45
if ( method . IsInitialized ) throw new InvalidOperationException ( "Sharing InjectionMethod between registrations is not supported" ) ;
46
46
47
47
// Select Method
48
- foreach ( var info in method . DeclaredMembers ( type ) )
48
+ foreach ( var info in type . GetDeclaredMethods ( ) )
49
49
{
50
50
if ( ! method . Data . MatchMemberInfo ( info ) ) continue ;
51
51
@@ -68,26 +68,34 @@ public static class Validating
68
68
if ( selection . IsStatic )
69
69
{
70
70
throw new ArgumentException (
71
- $ "The method { type ? . Name } . { method . Name } ( { method . Data . Signature ( ) } ) is static. Static methods cannot be injected. ") ;
71
+ $ "Static method { method . Name } on type ' { selection . DeclaringType . Name } ' cannot be injected") ;
72
72
}
73
73
74
+ if ( selection . IsPrivate )
75
+ throw new InvalidOperationException (
76
+ $ "Private method '{ method . Name } ' on type '{ selection . DeclaringType . Name } ' cannot be injected") ;
77
+
78
+ if ( selection . IsFamily )
79
+ throw new InvalidOperationException (
80
+ $ "Protected method '{ method . Name } ' on type '{ selection . DeclaringType . Name } ' cannot be injected") ;
81
+
74
82
if ( selection . IsGenericMethodDefinition )
75
83
{
76
84
throw new ArgumentException (
77
- $ "The method { type ? . Name } . { method . Name } ( { method . Data . Signature ( ) } ) is an open generic method. Open generic methods cannot be injected. ") ;
85
+ $ "Open generic method { method . Name } on type ' { selection . DeclaringType . Name } ' cannot be injected") ;
78
86
}
79
87
80
88
var parameters = selection . GetParameters ( ) ;
81
89
if ( parameters . Any ( param => param . IsOut ) )
82
90
{
83
91
throw new ArgumentException (
84
- $ "The method { type ? . Name } . { method . Name } ( { method . Data . Signature ( ) } ) has at least one out parameter . Methods with out parameters cannot be injected .") ;
92
+ $ "Method { method . Name } on type ' { selection . DeclaringType . Name } ' cannot be injected . Methods with ' out' parameters are not injectable .") ;
85
93
}
86
94
87
95
if ( parameters . Any ( param => param . ParameterType . IsByRef ) )
88
96
{
89
97
throw new ArgumentException (
90
- $ "The method { type ? . Name } . { method . Name } ( { method . Data . Signature ( ) } ) has at least one ref parameter. Methods with ref parameters cannot be injected .") ;
98
+ $ "Method { method . Name } on type ' { selection . DeclaringType . Name } ' cannot be injected. Methods with ' ref' parameters are not injectable .") ;
91
99
}
92
100
93
101
return selection ;
@@ -100,10 +108,11 @@ public static class Validating
100
108
FieldInfo selection = null ;
101
109
var field = ( InjectionMember < FieldInfo , object > ) member ;
102
110
103
- if ( field . IsInitialized ) throw new InvalidOperationException ( "Sharing InjectionField between registrations is not supported" ) ;
111
+ if ( field . IsInitialized ) throw new InvalidOperationException (
112
+ "Sharing InjectionField between registrations is not supported" ) ;
104
113
105
114
// Select Field
106
- foreach ( var info in field . DeclaredMembers ( type ) )
115
+ foreach ( var info in type . GetDeclaredFields ( ) )
107
116
{
108
117
if ( info . Name != field . Name ) continue ;
109
118
@@ -118,17 +127,25 @@ public static class Validating
118
127
$ "Injected field '{ field . Name } ' could not be matched with any public field on type '{ type ? . Name } '.") ;
119
128
}
120
129
130
+ if ( selection . IsStatic )
131
+ throw new InvalidOperationException (
132
+ $ "Static field '{ selection . Name } ' on type '{ type ? . Name } ' cannot be injected") ;
133
+
121
134
if ( selection . IsInitOnly )
122
- {
123
- throw new ArgumentException (
124
- $ "Field '{ selection . Name } ' on type '{ type ? . Name } ' is Read Only and can not be injected.") ;
125
- }
135
+ throw new InvalidOperationException (
136
+ $ "Readonly field '{ selection . Name } ' on type '{ type ? . Name } ' cannot be injected") ;
137
+
138
+ if ( selection . IsPrivate )
139
+ throw new InvalidOperationException (
140
+ $ "Private field '{ selection . Name } ' on type '{ type ? . Name } ' cannot be injected") ;
141
+
142
+ if ( selection . IsFamily )
143
+ throw new InvalidOperationException (
144
+ $ "Protected field '{ selection . Name } ' on type '{ type ? . Name } ' cannot be injected") ;
126
145
127
146
if ( ! field . Data . Matches ( selection . FieldType ) )
128
- {
129
147
throw new ArgumentException (
130
148
$ "Injected data '{ field . Data } ' could not be matched with type of field '{ selection . FieldType . Name } '.") ;
131
- }
132
149
133
150
return selection ;
134
151
} ;
@@ -144,7 +161,7 @@ public static class Validating
144
161
if ( property . IsInitialized ) throw new InvalidOperationException ( "Sharing InjectionProperty between registrations is not supported" ) ;
145
162
146
163
// Select Property
147
- foreach ( var info in property . DeclaredMembers ( type ) )
164
+ foreach ( var info in type . GetDeclaredProperties ( ) )
148
165
{
149
166
if ( info . Name != property . Name ) continue ;
150
167
@@ -156,14 +173,30 @@ public static class Validating
156
173
if ( null == selection )
157
174
{
158
175
throw new ArgumentException (
159
- $ "Injected property '{ property . Name } ' could not be matched with any public property on type '{ type ? . Name } '.") ;
176
+ $ "Injected property '{ property . Name } ' could not be matched with any property on type '{ type ? . Name } '.") ;
160
177
}
161
178
162
179
if ( ! selection . CanWrite )
163
- {
164
- throw new ArgumentException (
165
- $ "Property '{ selection . Name } ' on type '{ type ? . Name } ' is Read Only and can not be injected.") ;
166
- }
180
+ throw new InvalidOperationException (
181
+ $ "Readonly property '{ selection . Name } ' on type '{ type ? . Name } ' cannot be injected") ;
182
+
183
+ if ( 0 != selection . GetIndexParameters ( ) . Length )
184
+ throw new InvalidOperationException (
185
+ $ "Indexer '{ selection . Name } ' on type '{ type ? . Name } ' cannot be injected") ;
186
+
187
+ var setter = selection . GetSetMethod ( true ) ;
188
+
189
+ if ( setter . IsStatic )
190
+ throw new InvalidOperationException (
191
+ $ "Static property '{ selection . Name } ' on type '{ type ? . Name } ' cannot be injected") ;
192
+
193
+ if ( setter . IsPrivate )
194
+ throw new InvalidOperationException (
195
+ $ "Private property '{ selection . Name } ' on type '{ type ? . Name } ' cannot be injected") ;
196
+
197
+ if ( setter . IsFamily )
198
+ throw new InvalidOperationException (
199
+ $ "Protected property '{ selection . Name } ' on type '{ type ? . Name } ' cannot be injected") ;
167
200
168
201
if ( ! property . Data . Matches ( selection . PropertyType ) )
169
202
{
@@ -173,5 +206,6 @@ public static class Validating
173
206
174
207
return selection ;
175
208
} ;
209
+
176
210
}
177
211
}
0 commit comments