CreateMethod() 공개 메소드

Creates a method that matches the signature defined in the method parameter.
public CreateMethod ( Mono.Cecil.TypeDefinition targetType, MethodInfo method ) : Mono.Cecil.MethodDefinition
targetType Mono.Cecil.TypeDefinition The type that will host the new method.
method System.Reflection.MethodInfo The method from which the signature will be derived.
리턴 Mono.Cecil.MethodDefinition
예제 #1
0
        /// <summary>
        /// Generates a proxy that forwards all virtual method calls
        /// to a single <see cref="IInterceptor"/> instance.
        /// </summary>
        /// <param name="originalBaseType">The base class of the type being constructed.</param>
        /// <param name="baseInterfaces">The list of interfaces that the new type must implement.</param>
        /// <param name="module">The module that will hold the brand new type.</param>
        /// <param name="targetType">The <see cref="TypeDefinition"/> that represents the type to be created.</param>
        public virtual void Construct(Type originalBaseType, IEnumerable <Type> baseInterfaces,
                                      ModuleDefinition module, TypeDefinition targetType)
        {
            // Determine which interfaces need to be implemented
            var interfaces = new HashSet <Type>(baseInterfaces);

            // Implement the IProxy interface
            if (ProxyImplementor != null)
            {
                ProxyImplementor.Construct(module, targetType);
            }

            // Determine which methods should be proxied
            IEnumerable <MethodInfo> targetMethods = new MethodInfo[0];

            if (MethodPicker != null)
            {
                targetMethods = MethodPicker.ChooseProxyMethodsFrom(originalBaseType, interfaces);
            }

            if (ProxyMethodBuilder == null)
            {
                return;
            }

            // Generate a proxy method for each
            // target method
            foreach (var method in targetMethods)
            {
                ProxyMethodBuilder.CreateMethod(targetType, method);
            }
        }