Hi. It's really dumb, but I can't remove all methods from an assembly.
This code works for some namespaces, but for others it throws an error.
ModuleDefinition corlib = ModuleDefinition.ReadModule (typeof(
object).Module.FullyQualifiedName);
var voidctor = mainMod.Import (corlib.Types.FirstOrDefault (x => x.
Name == "Object" && x.Namespace == "System").Methods.FirstOrDefault (x => x.
Name == ".ctor"));
foreach (var type in mainMod.Types)
{
type.Methods.Clear ();
type.Methods.Add (new MethodDefinition (".ctor",
MethodAttributes.Public | MethodAttributes.HideBySig | MethodAttributes.
RTSpecialName | MethodAttributes.SpecialName, corlib.Import (typeof(void))))
;
MethodDefinition ctor = type.Methods [0];
ctor.Body.Instructions.Add (Instruction.Create (OpCodes.Ldarg_0
));
ctor.Body.Instructions.Add (Instruction.Create (OpCodes.Call,
voidctor));
ctor.Body.Instructions.Add (Instruction.Create (OpCodes.Ret));
}
The error is *Member 'System.Void .ctor()' is declared in another module
and needs to be imported.*
I am importing it though, and the code even works for some namespaces. I
don't understand...
--
--
--
mono-cecil
---
You received this message because you are subscribed to the Google Groups
"mono-cecil" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
For more options, visit https://groups.google.com/d/optout.