Ejemplo n.º 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);
            }
        }
Ejemplo n.º 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);
            }
        }
Ejemplo n.º 3
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)
        {
            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);
            }
        }
Ejemplo n.º 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);
            }
        }
Ejemplo n.º 5
0
 public void SetRemoveMethodWeaver(IMethodWeaver removeMethodWeaver)
 {
     this.removeMethodWeaver = removeMethodWeaver;
 }
Ejemplo n.º 6
0
 public void AddMethodWeaver(IMethodWeaver methodWeaver)
 {
     methodWeavers.Add(methodWeaver);
 }
Ejemplo n.º 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);
        }
Ejemplo n.º 8
0
 public void AddMethodWeaver(IMethodWeaver methodWeaver)
 {
     methodWeavers.Add(methodWeaver);
 }
Ejemplo n.º 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);
 }
Ejemplo n.º 10
0
 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;
 }
Ejemplo n.º 12
0
 public void SetGetMethodWeaver(IMethodWeaver getMethodWeaver)
 {
     this.getMethodWeaver = getMethodWeaver;
 }
Ejemplo n.º 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);
        }
Ejemplo n.º 14
0
 public void SetAddMethodWeaver(IMethodWeaver addMethodWeaver)
 {
     this.addMethodWeaver = addMethodWeaver;
 }
Ejemplo n.º 15
0
 public void SetGetMethodWeaver(IMethodWeaver getMethodWeaver)
 {
     this.getMethodWeaver = getMethodWeaver;
 }
Ejemplo n.º 16
0
 public void SetRaiseMethodWeaver(IMethodWeaver raiseMethodWeaver)
 {
     this.raiseMethodWeaver = raiseMethodWeaver;
 }
Ejemplo n.º 17
0
 public void SetRemoveMethodWeaver(IMethodWeaver removeMethodWeaver)
 {
     this.removeMethodWeaver = removeMethodWeaver;
 }
Ejemplo n.º 18
0
 public void SetAddMethodWeaver(IMethodWeaver addMethodWeaver)
 {
     this.addMethodWeaver = addMethodWeaver;
 }
Ejemplo n.º 19
0
 public void SetSetMethodWeaver(IMethodWeaver setMethodWeaver)
 {
     this.setMethodWeaver = setMethodWeaver;
 }
Ejemplo n.º 20
0
 public void SetRaiseMethodWeaver(IMethodWeaver raiseMethodWeaver)
 {
     this.raiseMethodWeaver = raiseMethodWeaver;
 }
Ejemplo n.º 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;
 }