Skip to content

Commit

Permalink
Find runtime in mock mode
Browse files Browse the repository at this point in the history
  • Loading branch information
Sergey Zabodalov committed Jan 18, 2022
1 parent 8d45021 commit 83e981e
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 9 deletions.
4 changes: 2 additions & 2 deletions src/Refasmer/Importer/MockupMethodBody.cs
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,9 @@ private EntityHandle FindOrCreateNotImplementedStringCtor()
return Import(ctorHandle);
}

var mscorlibRef = FindOrCreateMscorlibReference();
var runtimeRef = FindOrCreateRuntimeReference();

var notImplExceptionTypeRef = _builder.AddTypeReference(mscorlibRef, _builder.GetOrAddString("System"),
var notImplExceptionTypeRef = _builder.AddTypeReference(runtimeRef, _builder.GetOrAddString("System"),
_builder.GetOrAddString("NotImplementedException"));

var ctor = new BlobBuilder();
Expand Down
17 changes: 10 additions & 7 deletions src/Refasmer/Importer/Utils.cs
Original file line number Diff line number Diff line change
Expand Up @@ -78,22 +78,25 @@ private AssemblyReferenceHandle FindRuntimeReference()
return FindSystemRuntimeReference();
}

private AssemblyReferenceHandle FindOrCreateMscorlibReference()
private AssemblyReferenceHandle FindOrCreateRuntimeReference()
{
var mscorlibRef = FindMscorlibReference();
var runtimeRef = FindRuntimeReference();

if (!IsNil(mscorlibRef))
return mscorlibRef;
if (!IsNil(runtimeRef))
return runtimeRef;

// For now always creating ref to mscorlib
// TODO: try to detect which runtime should be referenced

mscorlibRef = _builder.AddAssemblyReference(
runtimeRef = _builder.AddAssemblyReference(
_builder.GetOrAddString("mscorlib"),
new Version(4, 0, 0, 0),
default, _builder.GetOrAddBlob(MscorlibPublicKeyBlob),
default, default);

Trace?.Invoke($"Created mscorlib assembly reference {RowId(mscorlibRef)}");
Trace?.Invoke($"Created mscorlib assembly reference {RowId(runtimeRef)}");

return mscorlibRef;
return runtimeRef;
}
}
}

0 comments on commit 83e981e

Please sign in to comment.