Exemple #1
0
        protected override Task OnInitializeAsync()
        {
            if (Request.Query.TryGetValue("baseType", out string baseTypeName))
            {
                if (!contentMetadataManager.TryGetMetadata(baseTypeName, out contentMetadataProvider))
                {
                    AddErrors("Not found content type.");
                    return(Task.CompletedTask);
                }
            }

            return(Task.CompletedTask);
        }
        public void TryGetMetadata()
        {
            var contentType     = typeof(TestPageContent);
            var contentMetadata = metadataManager.GetMetadata(contentType);

            Assert.True(metadataManager.TryGetMetadata(contentType, out ContentMetadataProvider contentMetadata2));
            Assert.Equal(contentMetadata, contentMetadata2);
        }
 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 ContentMetadataProvider GetMetadataByModelData(this IContentMetadataManager contentMetadataManager, IDictionary <string, object> modelData)
        {
            if (modelData == null)
            {
                throw new ArgumentNullException(nameof(modelData));
            }
            if (!modelData.TryGetValue(ContentMetadataProvider.ContentTypeNameDataKey, out object typeNameValue))
            {
                return(null);
            }

            contentMetadataManager.TryGetMetadata((string)typeNameValue, out ContentMetadataProvider contentMetadata);
            return(contentMetadata);
        }
        public static void ApplyInjections(this IContentMetadataManager contentMetadataManager, object model, IServiceProvider serviceProvider, bool injectInnerModels)
        {
            if (model == null)
            {
                throw new ArgumentNullException(nameof(model));
            }
            if (serviceProvider == null)
            {
                throw new ArgumentNullException(nameof(serviceProvider));
            }
            if (!contentMetadataManager.TryGetMetadata(model, out ContentMetadataProvider contentMetadataProvider))
            {
                throw new ArgumentException();
            }

            contentMetadataProvider.ApplyInjections(model, serviceProvider, injectInnerModels);
        }