Example #1
0
        // this runs only once the factory is ready
        // NOT when building models
        public IList CreateModelList(string alias)
        {
            var infos = EnsureModels();

            // fail fast
            if (infos == null)
            {
                return(new List <IPublishedElement>());
            }

            if (!infos.ModelInfos.TryGetValue(alias, out var modelInfo))
            {
                return(new List <IPublishedElement>());
            }

            var ctor = modelInfo.ListCtor;

            if (ctor != null)
            {
                return(ctor());
            }

            var listType = typeof(List <>).MakeGenericType(modelInfo.ModelType);

            ctor = modelInfo.ListCtor = ReflectionUtilities.EmitCtor <Func <IList> >(declaring: listType);
            return(ctor());
        }