Jump to content
Tuts 4 You

Resolve field with declaring type containing generic parameter


CodeExplorer

Recommended Posts

Posted

Resolve field with declaring type containing generic parameter

FieldDef dnlibfield = instructions[i].Operand as FieldDef;

if (!dnlibfield.DeclaringType.ContainsGenericParameter)
field = assembly.ManifestModule.ResolveField(dnlibfield.MDToken.ToInt32());
else
{
// here is the problem:
Type declType = assembly.ManifestModule.ResolveType(dnlibfield.DeclaringType.MDToken.ToInt32());

}

So how do use dnlib to resolve declaring type containing generic parameter ???

public virtual System.Reflection.FieldInfo? ResolveField(int metadataToken, Type[]? genericTypeArguments, Type[]? genericMethodArguments);

https://learn.microsoft.com/en-us/dotnet/api/system.reflection.module.resolvefield?view=net-9.0#system-reflection-module-resolvefield(system-int32-system-type()-system-type())
 

  • Like 1

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...