@@ -14,6 +14,7 @@ public partial class EcmaType
14
14
private TypeIdentifierData ComputeTypeIdentifierFromGuids ( )
15
15
{
16
16
CustomAttributeValue < TypeDesc > ? guidAttribute ;
17
+
17
18
if ( IsInterface && _typeDefinition . Attributes . HasFlag ( TypeAttributes . Import ) )
18
19
{
19
20
// ComImport interfaces get scope from their GUID
@@ -23,6 +24,7 @@ private TypeIdentifierData ComputeTypeIdentifierFromGuids()
23
24
{
24
25
// other equivalent types get it from the declaring assembly
25
26
var attributeHandle = this . MetadataReader . GetCustomAttributeHandle ( MetadataReader . GetAssemblyDefinition ( ) . GetCustomAttributes ( ) , "System.Runtime.InteropServices" , "GuidAttribute" ) ;
27
+
26
28
if ( attributeHandle . IsNil )
27
29
return null ;
28
30
@@ -40,6 +42,7 @@ private TypeIdentifierData ComputeTypeIdentifierFromGuids()
40
42
41
43
string scope = ( string ) guidAttribute . Value . FixedArguments [ 0 ] . Value ;
42
44
string name = this . Name ;
45
+
43
46
if ( this . Namespace != null )
44
47
name = this . Namespace + "." + name ;
45
48
@@ -53,6 +56,7 @@ private TypeIdentifierData ComputeTypeIdentifierData()
53
56
54
57
// Check for type identifier attribute
55
58
var typeIdentifierAttribute = this . GetDecodedCustomAttribute ( "System.Runtime.InteropServices" , "TypeIdentifierAttribute" ) ;
59
+
56
60
if ( typeIdentifierAttribute . HasValue )
57
61
{
58
62
// If the type has a type identifier attribute it is always considered to be type equivalent
@@ -68,28 +72,38 @@ private TypeIdentifierData ComputeTypeIdentifierData()
68
72
if ( typeIdentifierAttribute . Value . FixedArguments [ 1 ] . Type != Context . GetWellKnownType ( WellKnownType . String ) )
69
73
return null ;
70
74
71
- _data = new TypeIdentifierData ( ( string ) typeIdentifierAttribute . Value . FixedArguments [ 0 ] . Value , ( string ) typeIdentifierAttribute . Value . FixedArguments [ 1 ] . Value ) ;
72
- return _data ;
75
+ return new TypeIdentifierData ( ( string ) typeIdentifierAttribute . Value . FixedArguments [ 0 ] . Value , ( string ) typeIdentifierAttribute . Value . FixedArguments [ 1 ] . Value ) ;
73
76
}
74
- else
77
+
78
+ // In addition to the TypeIdentifierAttribute certain other types may also be opted in to type equivalence
79
+ if ( Context . SupportsCOMInterop )
75
80
{
76
- // In addition to the TypeIdentifierAttribute certain other types may also be opted in to type equivalence
77
- if ( Context . SupportsCOMInterop )
81
+ // 1. The assembly is marked with ImportedFromTypeLibAttribute or PrimaryInteropAssemblyAttribute
82
+ // We will verify this by checking for their attribute handles using the Metadata Reader.
83
+
84
+ CustomAttributeHandle importedFromTypeLibHdl = this . MetadataReader . GetCustomAttributeHandle (
85
+ MetadataReader . GetAssemblyDefinition ( ) . GetCustomAttributes ( ) ,
86
+ "System.Runtime.InteropServices" ,
87
+ "ImportedFromTypeLibAttribute"
88
+ ) ;
89
+
90
+ CustomAttributeHandle primaryInteropAssemblyHdl = this . MetadataReader . GetCustomAttributeHandle (
91
+ MetadataReader . GetAssemblyDefinition ( ) . GetCustomAttributes ( ) ,
92
+ "System.Runtime.InteropServices" ,
93
+ "PrimaryInteropAssemblyAttribute"
94
+ ) ;
95
+
96
+ if ( ! importedFromTypeLibHdl . IsNil || ! primaryInteropAssemblyHdl . IsNil )
78
97
{
79
- // 1. Type is within assembly marked with ImportedFromTypeLibAttribute or PrimaryInteropAssemblyAttribute
80
- if ( this . HasCustomAttribute ( "System.Runtime.InteropServices" , "ImportedFromTypeLibAttribute" ) || this . HasCustomAttribute ( "System.Runtime.InteropServices" , "PrimaryInteropAssemblyAttribute" ) )
81
- {
82
- // This type has a TypeIdentifier attribute if it has an appropriate shape to be considered type equivalent
83
- }
84
-
98
+ // This type has a TypeIdentifier attribute if it has an appropriate shape to be considered type equivalent
85
99
if ( ! TypeHasCharacteristicsRequiredToBeTypeEquivalent )
86
100
return null ;
87
101
88
- _data = ComputeTypeIdentifierFromGuids ( ) ;
102
+ return ComputeTypeIdentifierFromGuids ( ) ;
89
103
}
90
-
91
- return null ;
92
104
}
105
+
106
+ return null ;
93
107
}
94
108
95
109
public override TypeIdentifierData TypeIdentifierData
0 commit comments