private Type GetDecoratorTypeFromDecoratorFactory(Type requestedServiceType, DecoratorPredicateContext context) { Type decoratorType = this.data.DecoratorTypeFactory(context); if (decoratorType.Info().ContainsGenericParameters) { if (!requestedServiceType.Info().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.FactoryReturnsATypeThatIsAssignableFromServiceType(requestedServiceType, decoratorType); } return(decoratorType); }
private GenericTypeBuilder.BuildResult BuildClosedGenericImplementation( Type serviceType, Type decoratorTypeDefinition) { var builder = new GenericTypeBuilder(serviceType, decoratorTypeDefinition); return(builder.BuildClosedGenericImplementation()); }