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); }
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>(); }
private ContentExplorer(object model, ContentMetadataProvider contentMetadata) { Field = null; Model = model; Metadata = contentMetadata; ModelPath = string.Empty; Parent = null; rootExplorer = null; name = contentMetadata.Name; }
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); }
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); } } }