Skip to content

Commit

Permalink
'ldtoken GenericTypeDef/GenericTypeRef' is valid
Browse files Browse the repository at this point in the history
  • Loading branch information
CreateAndInject committed May 1, 2024
1 parent 04632a7 commit 8532a42
Showing 1 changed file with 8 additions and 5 deletions.
13 changes: 8 additions & 5 deletions src/DotNet/Emit/DynamicMethodBodyReader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -420,16 +420,16 @@ public MethodDef GetMethod() {
protected override string ReadInlineString(Instruction instr) => ReadToken(reader.ReadUInt32()) as string ?? string.Empty;

/// <inheritdoc/>
protected override ITokenOperand ReadInlineTok(Instruction instr) => ReadToken(reader.ReadUInt32()) as ITokenOperand;
protected override ITokenOperand ReadInlineTok(Instruction instr) => ReadToken(reader.ReadUInt32(), true) as ITokenOperand;

/// <inheritdoc/>
protected override ITypeDefOrRef ReadInlineType(Instruction instr) => ReadToken(reader.ReadUInt32()) as ITypeDefOrRef;

object ReadToken(uint token) {
object ReadToken(uint token, bool ldtoken = false) {
uint rid = token & 0x00FFFFFF;
switch (token >> 24) {
case 0x02:
return ImportType(rid);
return ImportType(rid, ldtoken);

case 0x04:
return ImportField(rid);
Expand Down Expand Up @@ -521,10 +521,13 @@ IField ImportField(uint rid) {
return null;
}

ITypeDefOrRef ImportType(uint rid) {
ITypeDefOrRef ImportType(uint rid, bool ldtoken) {
var obj = Resolve(rid);
if (obj is RuntimeTypeHandle)
if (obj is RuntimeTypeHandle) {
if (ldtoken)
return importer.Import(Type.GetTypeFromHandle((RuntimeTypeHandle)obj));
return importer.ImportAsOperand(Type.GetTypeFromHandle((RuntimeTypeHandle)obj));
}

return null;
}
Expand Down

0 comments on commit 8532a42

Please sign in to comment.