有什么方法可以从Mono.Cecil中的TypeReference转换为类型吗?
发布于 2014-07-29 20:52:51
对于泛型类型,您需要类似以下内容:
public static Type GetMonoType(this TypeReference type)
{
return Type.GetType(type.GetReflectionName(), true);
}
private static string GetReflectionName(this TypeReference type)
{
if (type.IsGenericInstance)
{
var genericInstance = (GenericInstanceType)type;
return string.Format("{0}.{1}[{2}]", genericInstance.Namespace, type.Name, String.Join(",", genericInstance.GenericArguments.Select(p => p.GetReflectionName()).ToArray()));
}
return type.FullName;
}
请注意,此代码不处理嵌套类型,请检查@çJohannesRudolph
https://stackoverflow.com/questions/4184384
复制相似问题