添加自定义属性使用Mono.Cecil能做到? [英] Adding custom attributes using mono.cecil?
本文介绍了添加自定义属性使用Mono.Cecil能做到?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想不出如何添加自定义属性使用Mono.Cecil能做到
,我会想添加的属性的方法是这样的:
I can't figure how to add custom attribute to a method using Mono.Cecil The attributes that I would want to add is like this :
.custom instance void [mscorlib]System.Diagnostics.DebuggerHiddenAttribute::.ctor() = ( 01 00 00 00 )
有谁知道如何添加自定义属性。
Does anyone know how to add custom attributes
推荐答案
这其实很。易
ModuleDefinition module = ...;
MethodDefinition targetMethod = ...;
MethodReference attributeConstructor = module.Import(
typeof(DebuggerHiddenAttribute).GetConstructor(Type.EmptyTypes));
targetMethod.CustomAttributes.Add(new CustomAttribute(attributeConstructor));
module.Write(...);
这篇关于添加自定义属性使用Mono.Cecil能做到?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文