private Type CheckForLazyAndPartCreator(Type type)
        {
            if (type.IsGenericType)
            {
                Type   genericType = type.GetGenericTypeDefinition();
                Type[] arguments   = type.GetGenericArguments();

                if (genericType == LazyOfTType)
                {
                    this._castSingleValue = ExportServices.CreateStronglyTypedLazyFactory(arguments[0], null);
                    return(arguments[0]);
                }

                if (genericType == LazyOfTMType)
                {
                    this.MetadataViewType = arguments[1];
                    this._castSingleValue = ExportServices.CreateStronglyTypedLazyFactory(arguments[0], arguments[1]);
                    return(arguments[0]);
                }

                if (
                    type.FullName.StartsWith(ExportFactoryTypeName, StringComparison.Ordinal) &&
                    ((arguments.Length == 1) || (arguments.Length == 2)))
                {
                    // Func<Tuple<T, Action>>
                    Type            exportLifetimeContextCreatorType = typeof(Func <>).MakeGenericType(typeof(Tuple <,>).MakeGenericType(arguments[0], typeof(Action)));
                    ConstructorInfo constructor = null;

                    if (arguments.Length == 1)
                    {
                        constructor = type.GetConstructor(new Type[] { exportLifetimeContextCreatorType });
                    }
                    else
                    {
                        Assumes.IsTrue(arguments.Length == 2);
                        constructor = type.GetConstructor(new Type[] { exportLifetimeContextCreatorType, arguments[1] });
                    }

                    if (constructor != null)
                    {
                        this.IsPartCreator = true;
                        if (arguments.Length == 1)
                        {
                            this._castSingleValue = ExportServices.CreateStronglyTypedExportFactoryFactory(arguments[0], null, constructor);
                        }
                        else
                        {
                            Assumes.IsTrue(arguments.Length == 2);
                            this._castSingleValue = ExportServices.CreateStronglyTypedExportFactoryFactory(arguments[0], arguments[1], constructor);
                            this.MetadataViewType = arguments[1];
                        }

                        return(arguments[0]);
                    }
                }
            }

            return(type);
        }
Exemple #2
0
        private Type CheckForLazyAndPartCreator(Type type)
        {
            if (type.IsGenericType)
            {
                Type   genericType = type.GetGenericTypeDefinition();
                Type[] arguments   = type.GetGenericArguments();

                if (genericType == LazyOfTType)
                {
                    this._castSingleValue = ExportServices.CreateStronglyTypedLazyFactory(arguments[0], null);
                    return(arguments[0]);
                }

                if (genericType == LazyOfTMType)
                {
                    this.MetadataViewType = arguments[1];
                    this._castSingleValue = ExportServices.CreateStronglyTypedLazyFactory(arguments[0], arguments[1]);
                    return(arguments[0]);
                }

                if (genericType == ExportFactoryOfTType || genericType == ExportFactoryOfTMType)
                {
                    this.IsPartCreator = true;
                    if (arguments.Length == 1)
                    {
                        this._castSingleValue = ExportServices.CreateStronglyTypedExportFactoryFactory(arguments[0], null);
                    }
                    else
                    {
                        Assumes.IsTrue(arguments.Length == 2);
                        this._castSingleValue = ExportServices.CreateStronglyTypedExportFactoryFactory(arguments[0], arguments[1]);
                        this.MetadataViewType = arguments[1];
                    }

                    return(arguments[0]);
                }
            }

            return(type);
        }