/// <summary> /// Modifies the current type using the given method weaver. /// </summary> /// <param name="targetType">The target type to be modified.</param> /// <param name="weaver">The method weaver that will modify the selected methods.</param> /// <param name="methodFilter">The method filter that will determine which methods should be modified.</param> public static void WeaveWith(this TypeDefinition targetType, IMethodWeaver weaver, Func <MethodReference, bool> methodFilter) { var methods = targetType.Methods.Where(m => m.HasBody && weaver.ShouldWeave(m) && methodFilter(m)) .ToArray(); foreach (var method in methods) { weaver.Weave(method); } }
/// <summary> /// Modifies the chosen types in an assembly using the given method weaver. /// </summary> /// <param name="targetAssembly">The target assembly that will be modified.</param> /// <param name="weaver">The method weaver that will be used to rewrite all the target methods.</param> /// <param name="typeFilter">The predicate that will determine which types will be modified.</param> public static void WeaveWith(this AssemblyDefinition targetAssembly, IMethodWeaver weaver, Func <TypeReference, bool> typeFilter) { var module = targetAssembly.MainModule; var types = module.Types.Where(t => typeFilter(t) && t.IsDefinition).ToArray(); var methods = types.SelectMany(t => t.Methods.Where(m => m.HasBody && weaver.ShouldWeave(m))).ToArray(); foreach (var method in methods) { weaver.Weave(method); } }
/// <summary> /// Applies a <see cref="IMethodWeaver"/> instance to all methods /// within the given <paramref name="targetType"/>. /// </summary> /// <param name="targetType">The target module.</param> /// <param name="weaver">The <see cref="ITypeWeaver"/> instance that will modify the methods in the given target type.</param> public static void WeaveWith(this TypeDefinition targetType, IMethodWeaver weaver) { var module = targetType.Module; var targetMethods = from MethodDefinition method in targetType.Methods where weaver.ShouldWeave(method) select method; // Modify the host module weaver.ImportReferences(module); // Add any additional members to the target type weaver.AddAdditionalMembers(targetType); foreach (var item in targetMethods) { weaver.Weave(item); } }
/// <summary> /// Applies a <see cref="IMethodWeaver"/> instance to all methods /// within the given <paramref name="targetType"/>. /// </summary> /// <param name="targetType">The target module.</param> /// <param name="weaver">The <see cref="ITypeWeaver"/> instance that will modify the methods in the given target type.</param> public static void WeaveWith(this TypeDefinition targetType, IMethodWeaver weaver) { ModuleDefinition module = targetType.Module; IEnumerable <MethodDefinition> targetMethods = from MethodDefinition method in targetType.Methods where weaver.ShouldWeave(method) select method; // Modify the host module weaver.ImportReferences(module); // Add any additional members to the target type weaver.AddAdditionalMembers(targetType); foreach (MethodDefinition item in targetMethods) { weaver.Weave(item); } }
public void SetRemoveMethodWeaver(IMethodWeaver removeMethodWeaver) { this.removeMethodWeaver = removeMethodWeaver; }
public void AddMethodWeaver(IMethodWeaver methodWeaver) { methodWeavers.Add(methodWeaver); }
/// <summary> /// Allows a <see cref="IMethodWeaver"/> instance to traverse any <see cref="IReflectionVisitable"/> /// instance. /// </summary> /// <param name="visitable">The visitable object.</param> /// <param name="methodWeaver">The method weaver.</param> public static void Accept(this IReflectionVisitable visitable, IMethodWeaver methodWeaver) { var visitor = new MethodWeaverVisitor(methodWeaver); visitable.Accept(visitor); }
public void SetSetMethodWeaver(IMethodWeaver setMethodWeaver) { this.setMethodWeaver = setMethodWeaver; }
/// <summary> /// Initializes a new instance of the MethodWeaverVisitor class. /// </summary> /// <param name="methodWeaver">The <see cref="IMethodWeaver"/> that will be used to modify a given type.</param> public MethodWeaverVisitor(IMethodWeaver methodWeaver) { _methodWeaver = methodWeaver; }
public void SetGetMethodWeaver(IMethodWeaver getMethodWeaver) { this.getMethodWeaver = getMethodWeaver; }
/// <summary> /// Modifies all the methods in an assembly using the given method weaver. /// </summary> /// <param name="targetAssembly">The target assembly to be modified.</param> /// <param name="weaver">The weaver that will perform the modification.</param> public static void WeaveWith(this AssemblyDefinition targetAssembly, IMethodWeaver weaver) { Func <MethodReference, bool> defaultFilter = m => m.IsDefinition; WeaveWith(targetAssembly, weaver, defaultFilter); }
public void SetAddMethodWeaver(IMethodWeaver addMethodWeaver) { this.addMethodWeaver = addMethodWeaver; }
public void SetRaiseMethodWeaver(IMethodWeaver raiseMethodWeaver) { this.raiseMethodWeaver = raiseMethodWeaver; }