Ejemplo n.º 1
0
        /// <summary>
        /// Creates a new <see cref="DefaultModelMetadata"/>.
        /// </summary>
        /// <param name="provider">The <see cref="IModelMetadataProvider"/>.</param>
        /// <param name="detailsProvider">The <see cref="ICompositeMetadataDetailsProvider"/>.</param>
        /// <param name="details">The <see cref="DefaultMetadataDetails"/>.</param>
        /// <param name="modelBindingMessageProvider">The <see cref="Metadata.DefaultModelBindingMessageProvider"/>.</param>
        public DefaultModelMetadata(
            IModelMetadataProvider provider,
            ICompositeMetadataDetailsProvider detailsProvider,
            DefaultMetadataDetails details,
            DefaultModelBindingMessageProvider modelBindingMessageProvider)
            : base(details.Key)
        {
            if (provider == null)
            {
                throw new ArgumentNullException(nameof(provider));
            }

            if (detailsProvider == null)
            {
                throw new ArgumentNullException(nameof(detailsProvider));
            }

            if (details == null)
            {
                throw new ArgumentNullException(nameof(details));
            }

            if (modelBindingMessageProvider == null)
            {
                throw new ArgumentNullException(nameof(modelBindingMessageProvider));
            }

            _provider                    = provider;
            _detailsProvider             = detailsProvider;
            _details                     = details;
            _modelBindingMessageProvider = modelBindingMessageProvider;
        }
        private DefaultModelMetadataProvider(
            ICompositeMetadataDetailsProvider detailsProvider,
            DefaultModelBindingMessageProvider modelBindingMessageProvider)
        {
            if (detailsProvider == null)
            {
                throw new ArgumentNullException(nameof(detailsProvider));
            }

            DetailsProvider             = detailsProvider;
            ModelBindingMessageProvider = modelBindingMessageProvider;

            _cacheEntryFactory = CreateCacheEntry;
            _metadataCacheEntryForObjectType = GetMetadataCacheEntryForObjectType();
        }
        /// <summary>
        /// Initializes a new instance of the <see cref="DefaultModelBindingMessageProvider"/> class based on
        /// <paramref name="originalProvider"/>.
        /// </summary>
        /// <param name="originalProvider">The <see cref="DefaultModelBindingMessageProvider"/> to duplicate.</param>
        public DefaultModelBindingMessageProvider(DefaultModelBindingMessageProvider originalProvider)
        {
            if (originalProvider == null)
            {
                throw new ArgumentNullException(nameof(originalProvider));
            }

            SetMissingBindRequiredValueAccessor(originalProvider.MissingBindRequiredValueAccessor);
            SetMissingKeyOrValueAccessor(originalProvider.MissingKeyOrValueAccessor);
            SetMissingRequestBodyRequiredValueAccessor(originalProvider.MissingRequestBodyRequiredValueAccessor);
            SetValueMustNotBeNullAccessor(originalProvider.ValueMustNotBeNullAccessor);
            SetAttemptedValueIsInvalidAccessor(originalProvider.AttemptedValueIsInvalidAccessor);
            SetNonPropertyAttemptedValueIsInvalidAccessor(originalProvider.NonPropertyAttemptedValueIsInvalidAccessor);
            SetUnknownValueIsInvalidAccessor(originalProvider.UnknownValueIsInvalidAccessor);
            SetNonPropertyUnknownValueIsInvalidAccessor(originalProvider.NonPropertyUnknownValueIsInvalidAccessor);
            SetValueIsInvalidAccessor(originalProvider.ValueIsInvalidAccessor);
            SetValueMustBeANumberAccessor(originalProvider.ValueMustBeANumberAccessor);
            SetNonPropertyValueMustBeANumberAccessor(originalProvider.NonPropertyValueMustBeANumberAccessor);
        }