Inheritance: IMethodPicker
Example #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);
            }
        }
Example #2
0
 /// <summary>
 /// Initializes the current class with the default values.
 /// </summary>
 public ProxyBuilder()
 {
     ProxyImplementor = new ProxyImplementor();
     MethodPicker = new MethodPicker();
     ProxyMethodBuilder = new ProxyMethodBuilder();
 }
Example #3
0
 /// <summary>
 /// Initializes the current class with the default values.
 /// </summary>
 public ProxyBuilder()
 {
     ProxyImplementor   = new ProxyImplementor();
     MethodPicker       = new MethodPicker();
     ProxyMethodBuilder = new ProxyMethodBuilder();
 }