Skip to content

Commit 9364e81

Browse files
authored
Fix writting MethodSpec (#210)
1 parent 9b6a8b4 commit 9364e81

File tree

3 files changed

+15
-24
lines changed

3 files changed

+15
-24
lines changed

MetadataProcessor.Shared/Extensions/MethodSpecificationExtensions.cs

Lines changed: 5 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -21,28 +21,15 @@ public static ushort ToEncodedNanoMethodToken(this MethodSpecification value)
2121

2222
public static NanoClrTable ToNanoCLRTable(this MethodSpecification value)
2323
{
24-
// this one has to be before the others because generic parameters are also "other" types
25-
if (value.Resolve() is MethodDefinition)
24+
if (value.DeclaringType.Scope.MetadataScopeType == MetadataScopeType.AssemblyNameReference)
2625
{
27-
return NanoClrTable.TBL_MethodDef;
28-
}
29-
else if (value.Resolve() is MethodReference ||
30-
value.Resolve() is MethodSpecification)
31-
{
32-
if (value.DeclaringType.Scope.MetadataScopeType == MetadataScopeType.AssemblyNameReference)
33-
{
34-
// method ref is external
35-
return NanoClrTable.TBL_MethodRef;
36-
}
37-
else
38-
{
39-
// method ref is internal
40-
return NanoClrTable.TBL_MethodDef;
41-
}
26+
// method ref is external
27+
return NanoClrTable.TBL_MethodRef;
4228
}
4329
else
4430
{
45-
throw new ArgumentException("Unknown conversion to CLR Table.");
31+
// method ref is internal
32+
return NanoClrTable.TBL_MethodDef;
4633
}
4734
}
4835
}

MetadataProcessor.Shared/Tables/nanoMethodSpecificationTable.cs

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -76,14 +76,14 @@ public nanoMethodSpecificationTable(
7676
/// <summary>
7777
/// Gets method specification ID if possible.
7878
/// </summary>
79-
/// <param name="genericParameter">Method reference metadata in Mono.Cecil format.</param>
79+
/// <param name="methodSpec">Method reference metadata in Mono.Cecil format.</param>
8080
/// <param name="referenceId">Method reference ID in .NET nanoFramework format.</param>
8181
/// <returns>Returns <c>true</c> if reference found, otherwise returns <c>false</c>.</returns>
8282
public bool TryGetMethodSpecificationId(
83-
MethodSpecification genericParameter,
83+
MethodSpecification methodSpec,
8484
out ushort referenceId)
8585
{
86-
return TryGetIdByValue(genericParameter, out referenceId);
86+
return TryGetIdByValue(methodSpec, out referenceId);
8787
}
8888

8989
/// <inheritdoc/>
@@ -101,11 +101,15 @@ protected override void WriteSingleItem(
101101
// Method
102102
if (_context.MethodDefinitionTable.TryGetMethodReferenceId(item.Resolve(), out ushort referenceId))
103103
{
104-
// method is method definition
104+
// method is method def
105+
}
106+
else if (_context.MethodReferencesTable.TryGetMethodReferenceId(item.ElementMethod, out referenceId))
107+
{
108+
// method is method ref
105109
}
106110
else
107111
{
108-
Debug.Fail($"Can't find a reference for {item.Resolve()}");
112+
Debug.Fail($"Can't find a reference for {item}");
109113
}
110114

111115
writer.WriteUInt16((ushort)(item.ToEncodedNanoMethodToken() | referenceId));

0 commit comments

Comments
 (0)