예제 #1
0
        /// <summary>
        /// Transforms the methods in the <paramref name="target"/> using the given method rewriter.
        /// </summary>
        /// <param name="target">The transformation target.</param>
        /// <param name="rewriter">The method rewriter.</param>
        /// <param name="filter">The method filter that determines which methods will be rewritten.</param>
        public static void WeaveWith(this IReflectionVisitable target, IMethodRewriter rewriter,
                                     Func <MethodReference, bool> filter)
        {
            var weaver = new MethodWeaver(rewriter, filter);

            target.Accept(weaver);
        }
예제 #2
0
        /// <summary>
        /// Modifies the current <paramref name="target"/> to support third-party method call interception.
        /// </summary>
        /// <param name="target">The target object.</param>
        /// <param name="typeFilter">The filter that will determine the target types that will be modified.</param>
        /// <param name="hostMethodFilter">The filter that will determine the methods that will be modified on the target type.</param>
        /// <param name="methodCallFilter">The filter that will determine which third-party methods will be intercepted on the target type.</param>
        public static void InterceptMethodCalls(this IReflectionVisitable target, Func <TypeReference, bool> typeFilter, Func <MethodReference, bool> hostMethodFilter, Func <MethodReference, bool> methodCallFilter)
        {
            var rewriter = new InterceptMethodCalls(hostMethodFilter, methodCallFilter);

            target.Accept(new ImplementModifiableType(typeFilter));
            target.WeaveWith(rewriter, hostMethodFilter);
        }
        /// <summary>
        /// Adds field interception support to the target type.
        /// </summary>
        /// <param name="targetType">The type that will be modified.</param>
        /// <param name="methodFilter">The filter that determines which methods on the target type will be modified to support field interception.</param>
        /// <param name="fieldFilter">The filter that determines which fields should be intercepted.</param>
        public static void InterceptFields(this IReflectionVisitable targetType, Func <MethodReference, bool> methodFilter, Func <FieldReference, bool> fieldFilter)
        {
            var typeWeaver  = new ImplementFieldInterceptionHostWeaver(t => true);
            var fieldWeaver = new InterceptFieldAccess(fieldFilter);

            targetType.WeaveWith(fieldWeaver, methodFilter);
            targetType.Accept(typeWeaver);
        }
        /// <summary>
        /// Modifies the current <paramref name="target"/> to support third-party method call interception for all method calls made inside the target.
        /// </summary>
        /// <param name="target">The target object.</param>
        /// <param name="methodCallFilter">The <see cref="IMethodCallFilter"/> instance that determines the method calls that will be intercepted.</param>
        /// <param name="hostMethodFilter">The <see cref="IMethodFilter"/> instance that determines the host method calls that will be modified</param>
        public static void InterceptMethodCalls(this IReflectionVisitable target, IMethodCallFilter methodCallFilter,
                                                IMethodFilter hostMethodFilter)
        {
            var rewriter = new InterceptMethodCalls(methodCallFilter);

            target.Accept(new ImplementModifiableType(GetDefaultTypeFilter()));
            target.WeaveWith(rewriter, hostMethodFilter.ShouldWeave);
        }
예제 #5
0
        public static void InterceptMethodBody(this IReflectionVisitable target,
                                               Func <MethodReference, bool> methodFilter, Func <TypeReference, bool> typeFilter)
        {
            target.Accept(new ImplementModifiableType(typeFilter));

            var interceptMethodBody = new InterceptMethodBody(methodFilter);

            target.WeaveWith(interceptMethodBody, methodFilter);
        }
        private void LoadNodeOnDemand(TreeNode node)
        {
            if (node.Nodes.ContainsKey(EXPANDER_NODE_KEY))
            {
                node.Nodes.RemoveAt(node.Nodes.IndexOfKey(EXPANDER_NODE_KEY));
            }
            if ((node.Tag) is IReflectionVisitable)
            {
                IReflectionVisitable visitable = (IReflectionVisitable)node.Tag;
                if (!m_visiteditems.ContainsKey(visitable))
                {
                    visitable.Accept(this);
                    m_visiteditems.Add(visitable, visitable);
                }
            }
            else if ((node.Tag) is IAssemblyWrapper)
            {
                IAssemblyWrapper iasm = (IAssemblyWrapper)node.Tag;

                IAssemblyContext context = PluginFactory.GetInstance().GetAssemblyContext(iasm.Location);
                if (context != null)
                {
                    AssemblyDefinition asmdef = context.AssemblyDefinition;

                    if ((AssemblyRestriction == null) || (asmdef == AssemblyRestriction))
                    {
                        m_nodes.Remove(node.Tag);
                        m_nodes.Add(asmdef, node);
                        node.Tag = asmdef;

                        foreach (ModuleDefinition moddef in asmdef.Modules)
                        {
                            AppendNode(asmdef, moddef, moddef.Types.Count > 0);
                        }
                    }
                    else
                    {
                        node.Tag = "restricted";
                        node.Text += String.Format(" (You can't use this assembly for selection -> restricted to {0})", AssemblyRestriction.Name.Name);
                    }
                }
            }
        }
예제 #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);
        }
예제 #8
0
        /// <summary>
        /// Allows a <see cref="ITypeWeaver"/> instance to traverse any <see cref="IReflectionVisitable"/>
        /// instance.
        /// </summary>
        /// <param name="visitable">The visitable object.</param>
        /// <param name="typeWeaver">The type weaver.</param>
        public static void Accept(this IReflectionVisitable visitable, ITypeWeaver typeWeaver)
        {
            var visitor = new TypeWeaverVisitor(typeWeaver);

            visitable.Accept(visitor);
        }