예제 #1
0
        private bool TryRegisterContentType(Type modelType, out ContentMetadataProvider contentMetadata)
        {
            if (TryGetMetadata(modelType, out contentMetadata))
            {
                return(true);
            }

            if (!TypeIsContent(modelType.GetTypeInfo()))
            {
                return(false);
            }

            ContentMetadataProvider baseMetadata = null;

            if (modelType.BaseType != null)
            {
                TryRegisterContentType(modelType.BaseType, out baseMetadata);
            }

            contentMetadata = new ContentMetadataProvider(this, modelType, baseMetadata);

            var index = metadataProviders.Count;

            metadataProviders.Add(contentMetadata);
            contentTypes.Add(modelType, index);
            contentNames.Add(contentMetadata.Name.ToLower(), index);

            return(true);
        }
        public void Implicit_Null_Type()
        {
            ContentMetadataProvider contentMetadata = null;
            var type = (Type)contentMetadata;

            Assert.Null(type);
        }
예제 #3
0
        public ContentManager(IContentStore <TEntry> store, IContentMetadataManager contentMetadataManager, IServiceProvider services)
        {
            this.contentMetadataManager = contentMetadataManager ?? throw new ArgumentNullException(nameof(contentMetadataManager));
            this.store    = store ?? throw new ArgumentNullException(nameof(store));
            this.services = services ?? throw new ArgumentNullException(nameof(services));

            modelMetadataProvider = contentMetadataManager.GetMetadata <TModel>();
        }
예제 #4
0
        private ContentExplorer(object model, ContentMetadataProvider contentMetadata)
        {
            Field     = null;
            Model     = model;
            Metadata  = contentMetadata;
            ModelPath = string.Empty;
            Parent    = null;

            rootExplorer = null;
            name         = contentMetadata.Name;
        }
예제 #5
0
        public bool TryGetMetadata(Type contentType, out ContentMetadataProvider metadata)
        {
            if (contentType == null)
            {
                throw new ArgumentNullException(nameof(contentType));
            }

            if (!contentTypes.TryGetValue(contentType, out int index))
            {
                metadata = null;
                return(false);
            }

            metadata = metadataProviders[index];
            return(true);
        }
        public static bool TryGetField <TField>(this ContentMetadataProvider contentMetadata, string fieldName, out TField field)
            where TField : class, Fields.IFieldProvider
        {
            if (!contentMetadata.TryGetField(fieldName, out Fields.IFieldProvider f))
            {
                field = null;
                return(false);
            }

            if (!(f is TField))
            {
                throw new ArgumentException();
            }

            field = (TField)f;
            return(true);
        }
예제 #7
0
        private ContentExplorer(ContentExplorer parent, IModelField field, int index, object model, ContentMetadataProvider contentMetadata)
        {
            Field    = field;
            Model    = model;
            Metadata = contentMetadata;
            Parent   = parent ?? throw new ArgumentNullException(nameof(parent));

            FieldPath = field.Name;
            if (index >= 0)
            {
                FieldPath += "[" + index + "]";
            }

            ModelPath = !parent.IsRoot ? string.Concat(parent.ModelPath, Delimiter, FieldPath) : FieldPath;
            Index     = index;

            rootExplorer = parent.rootExplorer ?? parent;
            name         = rootExplorer.name + ":" + ModelPath;
        }
 public static bool TryGetMetadata(this IContentMetadataManager contentMetadataManager, object model, out ContentMetadataProvider contentMetadataProvider)
 {
     if (model == null)
     {
         throw new ArgumentNullException(nameof(model));
     }
     return(contentMetadataManager.TryGetMetadata(model.GetType(), out contentMetadataProvider));
 }
        public static IEnumerable <ContentMetadataProvider> GetDerivedMetadataWithHierarhy(this ContentMetadataProvider contentMetadata, bool includeCurrent)
        {
            if (includeCurrent)
            {
                yield return(contentMetadata);
            }

            foreach (var derivedContentMetadata in contentMetadata.DerivedContents)
            {
                yield return(derivedContentMetadata);

                foreach (var childDerivedContentMetadata in GetDerivedMetadataWithHierarhy(derivedContentMetadata, false))
                {
                    yield return(childDerivedContentMetadata);
                }
            }
        }