@@ -146,9 +146,50 @@ public void Can_use_HasAttributeCached()
146
146
Assert . That ( typeof ( CharEnum ) . HasAttributeCached < EnumAsCharAttribute > ( ) ) ;
147
147
Assert . That ( typeof ( CharEnum ) . HasAttribute < EnumAsCharAttribute > ( ) ) ;
148
148
}
149
+
150
+ [ Test ]
151
+ public void Can_use_lazy_HasAttributeOf_APIs ( )
152
+ {
153
+ var props = typeof ( DeclarativeValidationTest ) . GetPublicProperties ( ) ;
154
+ Assert . That ( props . Length , Is . EqualTo ( 3 ) ) ;
155
+
156
+ var locationsProp = props . FirstOrDefault ( x =>
157
+ x . PropertyType != typeof ( string ) && x . PropertyType . GetTypeWithGenericInterfaceOf ( typeof ( IEnumerable < > ) ) != null ) ;
158
+
159
+ Assert . That ( locationsProp . Name , Is . EqualTo ( nameof ( DeclarativeValidationTest . Locations ) ) ) ;
160
+
161
+ var genericDef = locationsProp . PropertyType . GetTypeWithGenericInterfaceOf ( typeof ( IEnumerable < > ) ) ;
162
+ var elementType = genericDef . GetGenericArguments ( ) [ 0 ] ;
163
+ var elementProps = elementType . GetPublicProperties ( ) ;
164
+ var hasAnyChildValidators = elementProps
165
+ . Any ( elProp => elProp . HasAttributeOf < ValidateAttribute > ( ) ) ;
166
+ Assert . That ( hasAnyChildValidators ) ;
167
+ }
149
168
}
150
169
151
170
public class GenericType < T > { }
152
171
public class GenericType < T1 , T2 > { }
153
172
public class GenericType < T1 , T2 , T3 > { }
173
+
174
+ public class Location
175
+ {
176
+ public string Name { get ; set ; }
177
+ [ ValidateMaximumLength ( 20 ) ]
178
+ public string Value { get ; set ; }
179
+ }
180
+
181
+ public class DeclarativeValidationTest : IReturn < EmptyResponse >
182
+ {
183
+ [ ValidateNotEmpty ]
184
+ [ ValidateMaximumLength ( 20 ) ]
185
+ public string Site { get ; set ; }
186
+ public List < Location > Locations { get ; set ; } // **** here's the example
187
+ public List < NoValidators > NoValidators { get ; set ; }
188
+ }
189
+
190
+ public class NoValidators
191
+ {
192
+ public string Name { get ; set ; }
193
+ public string Value { get ; set ; }
194
+ }
154
195
}
0 commit comments