Example #1
0
        /// <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);
            }
        }
Example #2
0
        /// <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);
            }
        }
Example #4
0
        /// <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);
            }
        }
Example #5
0
 public void SetRemoveMethodWeaver(IMethodWeaver removeMethodWeaver)
 {
     this.removeMethodWeaver = removeMethodWeaver;
 }
Example #6
0
 public void AddMethodWeaver(IMethodWeaver methodWeaver)
 {
     methodWeavers.Add(methodWeaver);
 }
Example #7
0
        /// <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);
        }
Example #8
0
 public void AddMethodWeaver(IMethodWeaver methodWeaver)
 {
     methodWeavers.Add(methodWeaver);
 }
Example #9
0
 /// <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;
 }
Example #13
0
        /// <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);
        }
Example #14
0
 public void SetAddMethodWeaver(IMethodWeaver addMethodWeaver)
 {
     this.addMethodWeaver = addMethodWeaver;
 }
Example #15
0
 public void SetGetMethodWeaver(IMethodWeaver getMethodWeaver)
 {
     this.getMethodWeaver = getMethodWeaver;
 }
Example #16
0
 public void SetRaiseMethodWeaver(IMethodWeaver raiseMethodWeaver)
 {
     this.raiseMethodWeaver = raiseMethodWeaver;
 }
Example #17
0
 public void SetRemoveMethodWeaver(IMethodWeaver removeMethodWeaver)
 {
     this.removeMethodWeaver = removeMethodWeaver;
 }
Example #18
0
 public void SetAddMethodWeaver(IMethodWeaver addMethodWeaver)
 {
     this.addMethodWeaver = addMethodWeaver;
 }
Example #19
0
 public void SetSetMethodWeaver(IMethodWeaver setMethodWeaver)
 {
     this.setMethodWeaver = setMethodWeaver;
 }
Example #20
0
 public void SetRaiseMethodWeaver(IMethodWeaver raiseMethodWeaver)
 {
     this.raiseMethodWeaver = raiseMethodWeaver;
 }
Example #21
0
 /// <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;
 }