Mono.Cecil - 从 System.Type 获取 TypeReference

3

有没有可能获取分配给 System.Type 变量的类型的 TypeReferenceTypeDefinition

更具体地说,我正在尝试从以下属性定义中获取 String 类型:

Custom(Value=typeof(String))]
        public string SomeProperty {get; set;}
1个回答

6
你可以使用ModuleDefinition.ImportReference():
var a = AssemblyDefinition.ReadAssembly(typeof(Program).Assembly.Location);
var type = typeof(string);
var tr = a.MainModule.ImportReference(type);
var td = tr.Resolve();
Console.WriteLine($"tr = {tr}\ntd = {td}");

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接