如何删除所有DebuggerHiddenAttribute [英] How can I remove all DebuggerHiddenAttribute
问题描述
仅当编译器生成此属性时,如何才能从程序集中删除所有DebuggerHiddenAttribute?
How can I remove all DebuggerHiddenAttribute from an assembly only if the compiler generated this attribute?
我正在尝试此代码,但是它不起作用.
I'm trying this code, but it doesn't work.
ModuleDefinition module = ...;
MethodDefinition targetMethod = ...;
MethodReference attributeConstructor = module.Import(
typeof(DebuggerHiddenAttribute).GetConstructor(Type.EmptyTypes));
targetMethod.CustomAttributes.Remove(new CustomAttribute(attributeConstructor));
module.Write(...);
谢谢.
推荐答案
这实际上是不可能的.在已编译程序集中定义的属性是不可变的.您不能在不复制整个程序集的情况下进行更改.
This is not really possible. The attributes defined in a compiled assembly are immutable. You can't change them without reproducing the entire assembly.
在这个特定的答案中,当您调用Remove
时,它是在CustomAttributes
属性返回的数组上被调用的.它将从数组中删除它,而不是从程序集上的元数据中删除它
In this particular answer when you call Remove
it is being called on an array returned by the CustomAttributes
property. It will remove it from the array, not from the metadata on the assembly
这篇关于如何删除所有DebuggerHiddenAttribute的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!