【问题标题】:Mono.Cecil - Add new Attribute type to assemblyMono.Cecil - 向程序集添加新的属性类型
【发布时间】:2018-06-08 22:44:21
【问题描述】:

我正在尝试使用 Mono.Cecil 向程序集添加新的属性类型。

我希望它看起来像:

internal class ConfusedByAttribute : Attribute
{
}

但目前我得到了相同的结果,只是没有 : Attribute (System.Attribute) 部分。

这是我的代码:

var assemblyDef = AssemblyDefinition.ReadAssembly(args[0]);
var tp = new TypeDefinition(
    "", 
    "ConfusedByAttribute",
    Mono.Cecil.TypeAttributes.NestedPrivate);
assemblyDef.MainModule.Types.Add(tp);
assemblyDef.Write(args[0] + "neW");

感谢任何帮助,谢谢!

【问题讨论】:

标签: c# mono code-injection mono.cecil


【解决方案1】:

您需要添加 Attribute 作为基本类型:

tp.BaseType = assemblyDef.MainModule.ImportReference(typeof(Attribute));

【讨论】:

    猜你喜欢
    • 2012-12-13
    • 2015-07-28
    • 1970-01-01
    • 2018-02-25
    • 2012-01-13
    • 2011-09-05
    • 1970-01-01
    • 2011-06-13
    • 2019-09-21
    相关资源
    最近更新 更多