@@ -42,17 +42,13 @@ public static void DoPass(RewriteGlobalContext context)
42
42
}
43
43
44
44
string ? defaultMemberName = null ;
45
- var defaultMemberAttributeAttribute = type . CustomAttributes . FirstOrDefault ( it =>
46
- it . AttributeType ( ) ? . Name == "AttributeAttribute" && it . Signature ! . NamedArguments . Any ( it =>
47
- it . MemberName == "Name" && it . Argument . GetElementAsString ( ) == nameof ( DefaultMemberAttribute ) ) ) ;
48
- if ( defaultMemberAttributeAttribute != null )
45
+ if ( type . CustomAttributes . FirstOrDefault ( IsDefaultMemberAttributeFake ) != null )
49
46
{
50
47
defaultMemberName = "Item" ;
51
48
}
52
49
else
53
50
{
54
- var realDefaultMemberAttribute =
55
- type . CustomAttributes . FirstOrDefault ( it => it . AttributeType ( ) ? . Name == nameof ( DefaultMemberAttribute ) ) ;
51
+ var realDefaultMemberAttribute = type . CustomAttributes . FirstOrDefault ( IsDefaultMemberAttributeReal ) ;
56
52
if ( realDefaultMemberAttribute != null )
57
53
defaultMemberName = realDefaultMemberAttribute . Signature ? . FixedArguments [ 0 ] . Element ? . ToString ( ) ?? "Item" ;
58
54
}
@@ -63,6 +59,21 @@ public static void DoPass(RewriteGlobalContext context)
63
59
assemblyContext . Imports . Module . DefaultMemberAttribute ( ) . ToTypeDefOrRef ( ) , assemblyContext . Imports . Module . String ( ) ) ,
64
60
new CustomAttributeSignature ( new CustomAttributeArgument ( assemblyContext . Imports . Module . String ( ) , defaultMemberName ) ) ) ) ;
65
61
}
62
+
63
+ static bool IsDefaultMemberAttributeFake ( CustomAttribute attribute )
64
+ {
65
+ return attribute . AttributeType ( ) ? . Name == "AttributeAttribute" && attribute . Signature ! . NamedArguments . Any ( it =>
66
+ {
67
+ // Name support is for backwards compatibility.
68
+ return ( it . MemberName == "Type" && it . Argument . Element is ITypeDescriptor { Namespace : "System.Reflection" , Name : nameof ( DefaultMemberAttribute ) } )
69
+ || ( it . MemberName == "Name" && it . Argument . GetElementAsString ( ) == nameof ( DefaultMemberAttribute ) ) ;
70
+ } ) ;
71
+ }
72
+
73
+ static bool IsDefaultMemberAttributeReal ( CustomAttribute attribute )
74
+ {
75
+ return attribute . AttributeType ( ) is { Namespace . Value : "System.Reflection" , Name . Value : nameof ( DefaultMemberAttribute ) } ;
76
+ }
66
77
}
67
78
68
79
private static string UnmanglePropertyName ( AssemblyRewriteContext assemblyContext , PropertyDefinition prop ,
0 commit comments