@@ -546,6 +546,105 @@ public void DefineCustomAttributeFromBlob ()
546
546
module . Dispose ( ) ;
547
547
}
548
548
549
+ #if NET_CORE
550
+ [ Test ]
551
+ public void BoxedEnumOnGenericArgumentOnType ( )
552
+ {
553
+ TestCSharp ( "CustomAttributes.cs" , module => {
554
+ var valueEnumGenericType = module . GetType ( "BoxedValueEnumOnGenericType" ) ;
555
+
556
+ Assert . IsTrue ( valueEnumGenericType . HasCustomAttributes ) ;
557
+ Assert . AreEqual ( 1 , valueEnumGenericType . CustomAttributes . Count ) ;
558
+
559
+ var attribute = valueEnumGenericType . CustomAttributes [ 0 ] ;
560
+ Assert . AreEqual ( "System.Void FooAttribute::.ctor(System.Object,System.Object)" ,
561
+ attribute . Constructor . FullName ) ;
562
+
563
+ Assert . IsTrue ( attribute . HasConstructorArguments ) ;
564
+ Assert . AreEqual ( 2 , attribute . ConstructorArguments . Count ) ;
565
+
566
+ AssertCustomAttributeArgument ( "(Object:(GenericWithEnum`1/OnGenericNumber<System.Int32>:0))" , attribute . ConstructorArguments [ 0 ] ) ;
567
+ AssertCustomAttributeArgument ( "(Object:(GenericWithEnum`1/OnGenericNumber<System.String>:1))" , attribute . ConstructorArguments [ 1 ] ) ;
568
+ } ) ;
569
+ }
570
+
571
+ [ Test ]
572
+ public void EnumOnGenericArgumentOnType ( )
573
+ {
574
+ TestCSharp ( "CustomAttributes.cs" , module => {
575
+ var valueEnumGenericType = module . GetType ( "ValueEnumOnGenericType" ) ;
576
+
577
+ Assert . IsTrue ( valueEnumGenericType . HasCustomAttributes ) ;
578
+ Assert . AreEqual ( 1 , valueEnumGenericType . CustomAttributes . Count ) ;
579
+
580
+ var attribute = valueEnumGenericType . CustomAttributes [ 0 ] ;
581
+ Assert . AreEqual ( "System.Void FooAttribute::.ctor(GenericWithEnum`1/OnGenericNumber<Bingo>)" ,
582
+ attribute . Constructor . FullName ) ;
583
+
584
+ Assert . IsTrue ( attribute . HasConstructorArguments ) ;
585
+ Assert . AreEqual ( 1 , attribute . ConstructorArguments . Count ) ;
586
+
587
+ AssertCustomAttributeArgument ( "(GenericWithEnum`1/OnGenericNumber<Bingo>:1)" , attribute . ConstructorArguments [ 0 ] ) ;
588
+ } ) ;
589
+ }
590
+
591
+ [ Test ]
592
+ public void EnumOnGenericFieldOnType ( )
593
+ {
594
+ TestCSharp ( "CustomAttributes.cs" , module => {
595
+ var valueEnumGenericType = module . GetType ( "FieldEnumOnGenericType" ) ;
596
+
597
+ Assert . IsTrue ( valueEnumGenericType . HasCustomAttributes ) ;
598
+ Assert . AreEqual ( 1 , valueEnumGenericType . CustomAttributes . Count ) ;
599
+
600
+ var attribute = valueEnumGenericType . CustomAttributes [ 0 ] ;
601
+ var argument = attribute . Fields . Where ( a => a . Name == "NumberEnumField" ) . First ( ) . Argument ;
602
+
603
+ AssertCustomAttributeArgument ( "(GenericWithEnum`1/OnGenericNumber<System.Byte>:0)" , argument ) ;
604
+ } ) ;
605
+ }
606
+
607
+ [ Test ]
608
+ public void EnumOnGenericPropertyOnType ( )
609
+ {
610
+ TestCSharp ( "CustomAttributes.cs" , module => {
611
+ var valueEnumGenericType = module . GetType ( "PropertyEnumOnGenericType" ) ;
612
+
613
+ Assert . IsTrue ( valueEnumGenericType . HasCustomAttributes ) ;
614
+ Assert . AreEqual ( 1 , valueEnumGenericType . CustomAttributes . Count ) ;
615
+
616
+ var attribute = valueEnumGenericType . CustomAttributes [ 0 ] ;
617
+ var argument = attribute . Properties . Where ( a => a . Name == "NumberEnumProperty" ) . First ( ) . Argument ;
618
+
619
+ AssertCustomAttributeArgument ( "(GenericWithEnum`1/OnGenericNumber<System.Byte>:1)" , argument ) ;
620
+ } ) ;
621
+ }
622
+
623
+ [ Test ]
624
+ public void EnumDeclaredInGenericTypeArray ( )
625
+ {
626
+ TestCSharp ( "CustomAttributes.cs" , module => {
627
+ var type = module . GetType ( "WithAttributeUsingNestedEnumArray" ) ;
628
+ var attributes = type . CustomAttributes ;
629
+ Assert . AreEqual ( 1 , attributes . Count ) ;
630
+ var attribute = attributes [ 0 ] ;
631
+ Assert . AreEqual ( 1 , attribute . Fields . Count ) ;
632
+ var arg = attribute . Fields [ 0 ] . Argument ;
633
+ Assert . AreEqual ( "System.Object" , arg . Type . FullName ) ;
634
+
635
+ var argumentValue = ( CustomAttributeArgument ) arg . Value ;
636
+ Assert . AreEqual ( "GenericWithEnum`1/OnGenericNumber<System.String>[]" , argumentValue . Type . FullName ) ;
637
+ var argumentValues = ( CustomAttributeArgument [ ] ) argumentValue . Value ;
638
+
639
+ Assert . AreEqual ( "GenericWithEnum`1/OnGenericNumber<System.String>" , argumentValues [ 0 ] . Type . FullName ) ;
640
+ Assert . AreEqual ( 0 , ( int ) argumentValues [ 0 ] . Value ) ;
641
+
642
+ Assert . AreEqual ( "GenericWithEnum`1/OnGenericNumber<System.String>" , argumentValues [ 1 ] . Type . FullName ) ;
643
+ Assert . AreEqual ( 1 , ( int ) argumentValues [ 1 ] . Value ) ;
644
+ } ) ;
645
+ }
646
+ #endif
647
+
549
648
static void AssertCustomAttribute ( string expected , CustomAttribute attribute )
550
649
{
551
650
Assert . AreEqual ( expected , PrettyPrint ( attribute ) ) ;
@@ -643,7 +742,7 @@ static void PrettyPrint (TypeReference type, StringBuilder signature)
643
742
if ( type . IsArray ) {
644
743
ArrayType array = ( ArrayType ) type ;
645
744
signature . AppendFormat ( "{0}[]" , array . ElementType . etype . ToString ( ) ) ;
646
- } else if ( type . etype == ElementType . None ) {
745
+ } else if ( type . etype == ElementType . None || type . etype == ElementType . GenericInst ) {
647
746
signature . Append ( type . FullName ) ;
648
747
} else
649
748
signature . Append ( type . etype . ToString ( ) ) ;
0 commit comments