예제 #1
0
        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.CreateType();

#if DEBUG_SAVE_GENERATED_ASSEMBLY
            assemblyBuilder.Save("Unity_ILEmit_DynamicClasses.dll");
#endif
            return(result);
        }