【发布时间】:2012-05-04 02:20:38
【问题描述】:
此问题与this one 有关,但不是重复的。 Jb 在那里发布要添加自定义属性,以下 sn-p 将起作用:
ModuleDefinition module = ...;
MethodDefinition targetMethod = ...;
MethodReference attributeConstructor = module.Import(
typeof(DebuggerHiddenAttribute).GetConstructor(Type.EmptyTypes));
targetMethod.CustomAttributes.Add(new CustomAttribute(attributeConstructor));
module.Write(...);
我想使用类似的东西,但要添加一个自定义属性,其构造函数在其(唯一)构造函数中采用两个字符串参数,并且我想为那些(显然)指定值。有人可以帮忙吗?
【问题讨论】:
标签: c# mono.cecil