public int Implement(HashSet <Type> implementedInterfaces, int memberCount)
        {
            if (implementedInterfaces.Contains(this.@interface))
            {
                return(memberCount);
            }

            implementedInterfaces.Add(this.@interface);

            typeBuilder.AddInterfaceImplementation(this.@interface);

            foreach (MethodInfo method in MethodsToIntercept())
            {
                OverrideMethod(method, memberCount++);
            }

            foreach (PropertyInfo property in PropertiesToIntercept())
            {
                OverrideProperty(property, memberCount++);
            }

            foreach (EventInfo @event in EventsToIntercept())
            {
                OverrideEvent(@event, memberCount++);
            }

            foreach (var @extendedInterface in [email protected]())
            {
                memberCount =
                    new InterfaceImplementation(
                        this.typeBuilder,
                        @extendedInterface,
                        new GenericParameterMapper(@extendedInterface, this.genericParameterMapper),
                        this.proxyInterceptionPipelineField,
                        this.explicitImplementation,
                        this.targetField)
                    .Implement(implementedInterfaces, memberCount);
            }

            return(memberCount);
        }
        /// <summary>
        /// Create the wrapper class for the given type.
        /// </summary>
        /// <returns>Wrapper type.</returns>
        public Type GenerateType()
        {
            AddMethods();
            AddProperties();
            AddEvents();
            AddConstructors();

            int            memberCount           = 0;
            HashSet <Type> implementedInterfaces = GetImplementedInterfacesSet();

            foreach (var @interface in this.additionalInterfaces)
            {
                memberCount =
                    new InterfaceImplementation(this.typeBuilder, @interface, this.proxyInterceptionPipelineField, true)
                    .Implement(implementedInterfaces, memberCount);
            }

            Type result = typeBuilder.CreateTypeInfo().AsType();

            return(result);
        }
        public int Implement(HashSet<Type> implementedInterfaces, int memberCount)
        {
            if (implementedInterfaces.Contains(this.@interface))
            {
                return memberCount;
            }

            implementedInterfaces.Add(this.@interface);

            typeBuilder.AddInterfaceImplementation(this.@interface);

            foreach (MethodInfo method in MethodsToIntercept())
            {
                OverrideMethod(method, memberCount++);
            }

            foreach (PropertyInfo property in PropertiesToIntercept())
            {
                OverrideProperty(property, memberCount++);
            }

            foreach (EventInfo @event in EventsToIntercept())
            {
                OverrideEvent(@event, memberCount++);
            }

            foreach (var @extendedInterface in [email protected]())
            {
                memberCount =
                    new InterfaceImplementation(
                        this.typeBuilder,
                        @extendedInterface,
                        this.proxyInterceptionPipelineField,
                        this.explicitImplementation,
                        this.targetField)
                        .Implement(implementedInterfaces, memberCount);
            }

            return memberCount;
        }
        /// <summary>
        /// Create the wrapper class for the given type.
        /// </summary>
        /// <returns>Wrapper type.</returns>
        public Type GenerateType()
        {
            AddMethods();
            AddProperties();
            AddEvents();
            AddConstructors();

            int memberCount = 0;
            HashSet<Type> implementedInterfaces = GetImplementedInterfacesSet();
            foreach (var @interface in this.additionalInterfaces)
            {
                memberCount =
                    new InterfaceImplementation(this.typeBuilder, @interface, this.proxyInterceptionPipelineField, true)
                        .Implement(implementedInterfaces, memberCount);
            }

            Type result = typeBuilder.CreateType();
#if DEBUG_SAVE_GENERATED_ASSEMBLY
            assemblyBuilder.Save("Unity_ILEmit_DynamicClasses.dll");
#endif
            return result;
        }
예제 #5
0
        /// <summary>
        /// Create the wrapper class for the given type.
        /// </summary>
        /// <returns>Wrapper type.</returns>
        public Type GenerateType()
        {
            AddMethods();
            AddProperties();
            AddEvents();
            AddConstructors();

            int            memberCount           = 0;
            HashSet <Type> implementedInterfaces = GetImplementedInterfacesSet();

            foreach (var @interface in this.additionalInterfaces)
            {
                memberCount =
                    new InterfaceImplementation(this.typeBuilder, @interface, this.proxyInterceptionPipelineField, true)
                    .Implement(implementedInterfaces, memberCount);
            }

            Type result = typeBuilder.CreateType();

#if DEBUG_SAVE_GENERATED_ASSEMBLY
            assemblyBuilder.Save("Unity_ILEmit_DynamicClasses.dll");
#endif
            return(result);
        }
        /// <summary>
        /// Create the type to proxy the requested interface
        /// </summary>
        /// <returns></returns>
        public Type CreateProxyType()
        {
            HashSet<Type> implementedInterfaces = new HashSet<Type>();

            int memberCount =
                new InterfaceImplementation(
                    this.typeBuilder,
                    this.typeToIntercept,
                    this.mainInterfaceMapper,
                    this.proxyInterceptionPipelineField,
                    false,
                    this.targetField)
                    .Implement(implementedInterfaces, 0);

            foreach (var @interface in this.additionalInterfaces)
            {
                memberCount =
                    new InterfaceImplementation(
                        this.typeBuilder,
                        @interface,
                        this.proxyInterceptionPipelineField,
                        true)
                        .Implement(implementedInterfaces, memberCount);
            }

            AddConstructor();

            Type result = typeBuilder.CreateType();
            #if DEBUG_SAVE_GENERATED_ASSEMBLY
            assemblyBuilder.Save("Unity_ILEmit_InterfaceProxies.dll");
            #endif
            return result;
        }