private void MorphMethod(MethodDefinition method) { Tracer.TraceVerbose("Morph method: {0}", method.ToString()); if (method.IsConstructor && method.HasParameters) { AddMessage(Error.RoleCannotContainParameterizedConstructor(method.DeclaringType, method)); return; } bool remove = !method.RemainsInRoleInterface(); if (remove) { Defer(() => { method.DeclaringType.Methods.Remove(method); }); return; } if (method.IsFamily || method.IsFamilyOrAssembly) { // if the method is protected, mark it as guarded method.MarkAsGuarded(method.DeclaringType.Module); } method.Attributes = MethodAttributes.Public | MethodAttributes.HideBySig | // TODO: what about HideByName? MethodAttributes.NewSlot | MethodAttributes.Abstract | //MethodAttributes.Strict | // TODO: VB.NET uses this! MethodAttributes.Virtual; if (method.IsPropertyAccessor() || method.IsEventAccessor()) { method.Attributes |= MethodAttributes.SpecialName; } // the method body will be cleared in a wrap-up action Defer(() => { method.Body = null; }); }
private bool RemoveAccessor(MethodDefinition accessor) { return !accessor.RemainsInRoleInterface(); }
private void AdjustCalls(MethodDefinition sourceMethod, MethodDefinition staticMethod) { if (sourceMethod.IsConstructor) { // remove base class constructor call ( : base(...) ) // other constructor calls ( : this(...) ) are not present because roles cannot have parameterized constructors RemoveBaseClassConstructorCall(staticMethod); } else { if (!sourceMethod.RemainsInRoleInterface()) { // methods that are removed from the role interface must have their callees adjusted to call directly the method in the Code class // constructors are an not included because calling a role constructor is an error AdjustMethodCalls(sourceMethod, staticMethod); } } }