/// <summary> /// Creates the advice wrapper and adds it to implementation. /// </summary> /// <param name="interfaceMethod">The interface method.</param> /// <param name="implementationType">Type of the implementation.</param> /// <param name="injectAsPrivate">if set to <c>true</c> [inject as private].</param> /// <param name="context">The context.</param> /// <returns></returns> private MethodDef WeaveInterfaceMethod(MethodDef interfaceMethod, TypeDef implementationType, bool injectAsPrivate, WeavingContext context) { var module = implementationType.Module; var typeImporter = new TypeImporter(module); var methodAttributes = MethodAttributes.NewSlot | MethodAttributes.Virtual | (injectAsPrivate ? MethodAttributes.Public : MethodAttributes.Private); var implementationMethodSig = interfaceMethod.MethodSig.Clone(); var implementationMethod = new MethodDefUser(interfaceMethod.Name, /*interfaceMethod.MethodSig */ implementationMethodSig, methodAttributes); for (int parameterIndex = 0; parameterIndex < implementationMethod.Parameters.Count; parameterIndex++) { var parameterType = implementationMethod.Parameters[parameterIndex].Type; if (parameterType != null) { var relocatedParameterType = typeImporter.TryRelocateTypeSig(parameterType) ?? parameterType; implementationMethod.Parameters[parameterIndex].Type = module.Import(relocatedParameterType); } } if (implementationMethod.HasReturnType) { var relocatedReturnType = typeImporter.TryRelocateTypeSig(implementationMethod.ReturnType) ?? implementationMethod.ReturnType; implementationMethod.ReturnType = relocatedReturnType; } implementationMethod.GenericParameters.AddRange(interfaceMethod.GenericParameters); implementationType.Methods.Add(implementationMethod); var interfaceMethodRef = module.Import(interfaceMethod); implementationMethod.Overrides.Add(new MethodOverride(implementationMethod, interfaceMethodRef)); WritePointcutBody(implementationMethod, null, false, context); return(implementationMethod); }