Пример #1
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);
            }
        }
Пример #2
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);
            }
        }
Пример #3
0
 /// <summary>
 /// Visits a <see cref="ModuleDefinition"/> instance.
 /// </summary>
 /// <param name="module">A <see cref="ModuleDefinition"/> object.</param>
 public override void VisitModuleDefinition(ModuleDefinition module)
 {
     _methodWeaver.ImportReferences(module);
     base.VisitModuleDefinition(module);
 }