Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -21,28 +21,15 @@ public static ushort ToEncodedNanoMethodToken(this MethodSpecification value)

public static NanoClrTable ToNanoCLRTable(this MethodSpecification value)
{
// this one has to be before the others because generic parameters are also "other" types
if (value.Resolve() is MethodDefinition)
if (value.DeclaringType.Scope.MetadataScopeType == MetadataScopeType.AssemblyNameReference)
{
return NanoClrTable.TBL_MethodDef;
}
else if (value.Resolve() is MethodReference ||
value.Resolve() is MethodSpecification)
{
if (value.DeclaringType.Scope.MetadataScopeType == MetadataScopeType.AssemblyNameReference)
{
// method ref is external
return NanoClrTable.TBL_MethodRef;
}
else
{
// method ref is internal
return NanoClrTable.TBL_MethodDef;
}
// method ref is external
return NanoClrTable.TBL_MethodRef;
}
else
{
throw new ArgumentException("Unknown conversion to CLR Table.");
// method ref is internal
return NanoClrTable.TBL_MethodDef;
}
}
}
Expand Down
14 changes: 9 additions & 5 deletions MetadataProcessor.Shared/Tables/nanoMethodSpecificationTable.cs
Original file line number Diff line number Diff line change
Expand Up @@ -76,14 +76,14 @@ public nanoMethodSpecificationTable(
/// <summary>
/// Gets method specification ID if possible.
/// </summary>
/// <param name="genericParameter">Method reference metadata in Mono.Cecil format.</param>
/// <param name="methodSpec">Method reference metadata in Mono.Cecil format.</param>
/// <param name="referenceId">Method reference ID in .NET nanoFramework format.</param>
/// <returns>Returns <c>true</c> if reference found, otherwise returns <c>false</c>.</returns>
public bool TryGetMethodSpecificationId(
MethodSpecification genericParameter,
MethodSpecification methodSpec,
out ushort referenceId)
{
return TryGetIdByValue(genericParameter, out referenceId);
return TryGetIdByValue(methodSpec, out referenceId);
}

/// <inheritdoc/>
Expand All @@ -101,11 +101,15 @@ protected override void WriteSingleItem(
// Method
if (_context.MethodDefinitionTable.TryGetMethodReferenceId(item.Resolve(), out ushort referenceId))
{
// method is method definition
// method is method def
}
else if (_context.MethodReferencesTable.TryGetMethodReferenceId(item.ElementMethod, out referenceId))
{
// method is method ref
}
else
{
Debug.Fail($"Can't find a reference for {item.Resolve()}");
Debug.Fail($"Can't find a reference for {item}");
}

writer.WriteUInt16((ushort)(item.ToEncodedNanoMethodToken() | referenceId));
Expand Down