Ejemplo n.º 1
0
        public ProxySyntaxFactory(
            ITypeInfo interfaceType,
            ITypeInfo interceptorType,
            string?containingAssembly,
            OutputType outputType,
            ReferenceCollector?referenceCollector) : base(outputType, containingAssembly ?? $"Proxy_{interceptorType.GetMD5HashCode()}", referenceCollector)
        {
            if (!interfaceType.IsInterface)
            {
                throw new ArgumentException(Resources.NOT_AN_INTERFACE, nameof(interfaceType));
            }

            if (interfaceType is IGenericTypeInfo genericIface && genericIface.IsGenericDefinition)
            {
                throw new ArgumentException(Resources.GENERIC_IFACE, nameof(interfaceType));
            }

            string baseInterceptorName = typeof(InterfaceInterceptor <>).FullName;

            IGenericTypeInfo?baseInterceptor = (IGenericTypeInfo?)
                                               (
                interceptorType.QualifiedName == baseInterceptorName
                    ? interceptorType
                    : interceptorType.GetBaseTypes().Single(ic => ic.QualifiedName == baseInterceptorName, throwOnEmpty: false)
                                               );

            if (baseInterceptor?.GenericArguments?.Single()?.EqualsTo(interfaceType) is not true)
            {
                throw new ArgumentException(Resources.NOT_AN_INTERCEPTOR, nameof(interceptorType));
            }

            if (interceptorType is IGenericTypeInfo genericInterceptor && genericInterceptor.IsGenericDefinition)
            {
                throw new ArgumentException(Resources.GENERIC_INTERCEPTOR, nameof(interceptorType));
            }

            InterfaceType   = interfaceType;
            InterceptorType = interceptorType;

            Invoke = InterceptorType.Methods.Single
                     (
Ejemplo n.º 2
0
        public ProxySyntaxFactory(ITypeInfo interfaceType, ITypeInfo interceptorType, string containingAssembly, OutputType outputType, ITypeInfo relatedGenerator) : base(outputType, containingAssembly, relatedGenerator)
        {
            if (!interfaceType.IsInterface)
            {
                throw new ArgumentException(Resources.NOT_AN_INTERFACE, nameof(interfaceType));
            }

            if (interfaceType is IGenericTypeInfo genericIface && genericIface.IsGenericDefinition)
            {
                throw new ArgumentException(Resources.GENERIC_IFACE, nameof(interfaceType));
            }

            //
            // - Append() hivas azon perverz esetre ha nem szarmaztunk le az InterfaceInterceptor-bol
            // - A "FullName" nem veszi figyelembe a generikus argumentumokat, ami nekunk pont jo
            //

            if (!interceptorType.GetBaseTypes().Append(interceptorType).Any(ic => ic.QualifiedName == typeof(InterfaceInterceptor <>).FullName))
            {
                throw new ArgumentException(Resources.NOT_AN_INTERCEPTOR, nameof(interceptorType));
            }

            if (interceptorType is IGenericTypeInfo genericInterceptor && genericInterceptor.IsGenericDefinition)
            {
                throw new ArgumentException(Resources.GENERIC_INTERCEPTOR, nameof(interceptorType));
            }

            InterfaceType   = interfaceType;
            InterceptorType = interceptorType;
            ClassName       = $"GeneratedClass_{InterceptorType.GetMD5HashCode()}";

            MemberSyntaxFactories = new IMemberSyntaxFactory[]
            {
                new ConstructorFactory(this),
                new InvokeFactory(this),
                new MethodInterceptorFactory(this),
                new PropertyInterceptorFactory(this),
                new EventInterceptorFactory(this)
            };
        }