@@ -229,6 +229,22 @@ public void CustomAttributesTest(Type attrType)
229229 Assert . True ( prov . IsDefined ( attrType , true ) ) ;
230230 }
231231
232+ [ Theory ]
233+ [ InlineData ( 0 , true , 30 ) ]
234+ [ InlineData ( 1 , false , - 1 ) ]
235+ [ InlineData ( 2 , true , 50 ) ]
236+ public void CustomAttributesInheritanceTest ( int paramIndex , bool exists , int expectedMyAttributeValue )
237+ {
238+ ParameterInfo parameterInfo = GetParameterInfo ( typeof ( DerivedParameterInfoMetadata ) , "VirtualMethodWithCustomAttributes" , paramIndex ) ;
239+ CustomAttributeData attribute = parameterInfo . CustomAttributes . SingleOrDefault ( a => a . AttributeType . Equals ( typeof ( MyAttribute ) ) ) ;
240+ Assert . Equal ( exists , attribute != null ) ;
241+
242+ ICustomAttributeProvider prov = parameterInfo as ICustomAttributeProvider ;
243+ MyAttribute myAttribute = prov . GetCustomAttributes ( typeof ( MyAttribute ) , true ) . SingleOrDefault ( ) as MyAttribute ;
244+ Assert . Equal ( exists , myAttribute != null ) ;
245+ Assert . Equal ( expectedMyAttributeValue , exists ? myAttribute . Value : expectedMyAttributeValue ) ;
246+ }
247+
232248 [ Fact ]
233249 public void VerifyGetCustomAttributesData ( )
234250 {
@@ -345,6 +361,7 @@ public void Foo2([CustomBindingFlags(Value = BindingFlags.IgnoreCase)] BindingFl
345361 public void Foo3 ( [ CustomBindingFlags ( Value = BindingFlags . DeclaredOnly ) ] BindingFlags bf = BindingFlags . FlattenHierarchy ) { }
346362
347363 public void MethodWithCustomAttribute ( [ My ( 2 ) ] string str , int iValue , long lValue ) { }
364+ public virtual void VirtualMethodWithCustomAttributes ( [ My ( 3 ) ] int val1 , [ My ( 4 ) ] int val2 , int val3 ) { }
348365
349366 public void Method1 ( string str , int iValue , long lValue ) { }
350367 public void Method2 ( ) { }
@@ -372,6 +389,11 @@ public void MethodWithNullableEnum(AttributeTargets? arg = AttributeTargets.All)
372389 public int MethodWithOptionalDefaultOutInMarshalParam ( [ MarshalAs ( UnmanagedType . LPWStr ) ] [ Out ] [ In ] string str = "" ) { return 1 ; }
373390 }
374391
392+ public class DerivedParameterInfoMetadata : ParameterInfoMetadata
393+ {
394+ override public void VirtualMethodWithCustomAttributes ( [ My ( 30 ) ] int val1 , int val2 , [ My ( 50 ) ] int val3 ) { }
395+ }
396+
375397 public class GenericClass < T >
376398 {
377399 public void GenericMethod ( T t ) { }
@@ -380,7 +402,8 @@ public void GenericMethod(T t) { }
380402
381403 private class MyAttribute : Attribute
382404 {
383- internal MyAttribute ( int i ) { }
405+ public int Value { get ; private set ; }
406+ internal MyAttribute ( int i ) { Value = i ; }
384407 }
385408
386409 internal sealed class CustomBindingFlagsAttribute : UsableCustomConstantAttribute
0 commit comments