Exemple #1
0
        internal static Type MakeClosedImplementation(Type closedAbstraction, Type openImplementation)
        {
            var builder = new GenericTypeBuilder(closedAbstraction, openImplementation);
            var results = builder.BuildClosedGenericImplementation();

            return(results.ClosedGenericImplementation);
        }
 internal static Type MakeClosedImplementation(Type closedAbstraction, Type openImplementation)
 {
     var builder = new GenericTypeBuilder(closedAbstraction, openImplementation);
     var results = builder.BuildClosedGenericImplementation();
     return results.ClosedGenericImplementation;
 }
        private GenericTypeBuilder.BuildResult BuildClosedGenericImplementation(Type serviceType)
        {
            var builder = new GenericTypeBuilder(serviceType, this.DecoratorTypeDefinition);

            return builder.BuildClosedGenericImplementation();
        }
        private Type GetDecoratorTypeFromDecoratorFactory(Type requestedServiceType, 
            DecoratorPredicateContext context)
        {
            Type decoratorType = this.data.DecoratorTypeFactory(context);

            if (decoratorType.ContainsGenericParameters)
            {
                if (!requestedServiceType.IsGenericType)
                {
                    throw new ActivationException(
                        StringResources.TheDecoratorReturnedFromTheFactoryShouldNotBeOpenGeneric(
                            requestedServiceType, decoratorType));
                }

                Requires.TypeFactoryReturnedTypeThatDoesNotContainUnresolvableTypeArguments(
                    requestedServiceType, decoratorType);

                var builder = new GenericTypeBuilder(requestedServiceType, decoratorType);

                decoratorType = builder.BuildClosedGenericImplementation().ClosedGenericImplementation;

                // decoratorType == null when type constraints don't match.
                if (decoratorType != null)
                {
                    Requires.HasFactoryCreatedDecorator(this.data.Container, requestedServiceType, decoratorType);
                }
            }
            else
            {
                Requires.DecoratorFactoryReturnsATypeThatIsAssignableFromServiceType(decoratorType, requestedServiceType);
            }

            return decoratorType;
        }