문제

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(...);

Thanks in advance.

도움이 되었습니까?

해결책

This is not really possible. The attributes defined in a compiled assembly are immutable. You can't change them without reproducing the entire assembly.

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

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top