private void ResolveCallsToBaseMethod(MethodDefinition method) { // Note: deciding if a call is a base method call is too hard in general, // it's necessary to trace the stack until an ldarg.0 is found. // Since Object is the only base class supported for roles at the moment, // this is simpler. // Look for calls (not callvirt) to methods in Object var body = method.GetBody(); if (body == null) return; foreach (Instruction instruction in body.Instructions) { if (instruction.OpCode == OpCodes.Call) { var calleeReference = (MethodReference)instruction.Operand; var callee = calleeReference.Resolve(); if (!callee.IsConstructor && !callee.IsStatic && callee.DeclaringType == _context.Module.Import(typeof(object)).Resolve()) { _callsToBaseMethods.Add(instruction); } } } }
private void ExtractMethodBody(MethodDefinition sourceMethod, MethodDefinition staticMethod) { // copy the method's body staticMethod.Body = sourceMethod.GetBody(); // TODO: clone? }