@@ -45,7 +45,7 @@ public static class Validating
4545 if ( method . IsInitialized ) throw new InvalidOperationException ( "Sharing InjectionMethod between registrations is not supported" ) ;
4646
4747 // Select Method
48- foreach ( var info in method . DeclaredMembers ( type ) )
48+ foreach ( var info in type . GetDeclaredMethods ( ) )
4949 {
5050 if ( ! method . Data . MatchMemberInfo ( info ) ) continue ;
5151
@@ -68,26 +68,34 @@ public static class Validating
6868 if ( selection . IsStatic )
6969 {
7070 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") ;
7272 }
7373
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+
7482 if ( selection . IsGenericMethodDefinition )
7583 {
7684 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") ;
7886 }
7987
8088 var parameters = selection . GetParameters ( ) ;
8189 if ( parameters . Any ( param => param . IsOut ) )
8290 {
8391 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 .") ;
8593 }
8694
8795 if ( parameters . Any ( param => param . ParameterType . IsByRef ) )
8896 {
8997 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 .") ;
9199 }
92100
93101 return selection ;
@@ -100,10 +108,11 @@ public static class Validating
100108 FieldInfo selection = null ;
101109 var field = ( InjectionMember < FieldInfo , object > ) member ;
102110
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" ) ;
104113
105114 // Select Field
106- foreach ( var info in field . DeclaredMembers ( type ) )
115+ foreach ( var info in type . GetDeclaredFields ( ) )
107116 {
108117 if ( info . Name != field . Name ) continue ;
109118
@@ -118,17 +127,25 @@ public static class Validating
118127 $ "Injected field '{ field . Name } ' could not be matched with any public field on type '{ type ? . Name } '.") ;
119128 }
120129
130+ if ( selection . IsStatic )
131+ throw new InvalidOperationException (
132+ $ "Static field '{ selection . Name } ' on type '{ type ? . Name } ' cannot be injected") ;
133+
121134 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") ;
126145
127146 if ( ! field . Data . Matches ( selection . FieldType ) )
128- {
129147 throw new ArgumentException (
130148 $ "Injected data '{ field . Data } ' could not be matched with type of field '{ selection . FieldType . Name } '.") ;
131- }
132149
133150 return selection ;
134151 } ;
@@ -144,7 +161,7 @@ public static class Validating
144161 if ( property . IsInitialized ) throw new InvalidOperationException ( "Sharing InjectionProperty between registrations is not supported" ) ;
145162
146163 // Select Property
147- foreach ( var info in property . DeclaredMembers ( type ) )
164+ foreach ( var info in type . GetDeclaredProperties ( ) )
148165 {
149166 if ( info . Name != property . Name ) continue ;
150167
@@ -156,14 +173,30 @@ public static class Validating
156173 if ( null == selection )
157174 {
158175 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 } '.") ;
160177 }
161178
162179 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") ;
167200
168201 if ( ! property . Data . Matches ( selection . PropertyType ) )
169202 {
@@ -173,5 +206,6 @@ public static class Validating
173206
174207 return selection ;
175208 } ;
209+
176210 }
177211}
0 commit comments