Пример #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.ModelBindingMessageProvider"/>.</param>
        public DefaultModelMetadata(
            IModelMetadataProvider provider,
            ICompositeMetadataDetailsProvider detailsProvider,
            DefaultMetadataDetails details,
            ModelBindingMessageProvider 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;
        }
        /// <summary>
        /// Initializes a new instance of the <see cref="ModelBindingMessageProvider"/> class based on
        /// <paramref name="originalProvider"/>.
        /// </summary>
        /// <param name="originalProvider">The <see cref="ModelBindingMessageProvider"/> to duplicate.</param>
        public ModelBindingMessageProvider(ModelBindingMessageProvider originalProvider)
        {
            if (originalProvider == null)
            {
                throw new ArgumentNullException(nameof(originalProvider));
            }

            MissingBindRequiredValueAccessor = originalProvider.MissingBindRequiredValueAccessor;
            MissingKeyOrValueAccessor        = originalProvider.MissingKeyOrValueAccessor;
            ValueMustNotBeNullAccessor       = originalProvider.ValueMustNotBeNullAccessor;
            AttemptedValueIsInvalidAccessor  = originalProvider.AttemptedValueIsInvalidAccessor;
            UnknownValueIsInvalidAccessor    = originalProvider.UnknownValueIsInvalidAccessor;
            ValueIsInvalidAccessor           = originalProvider.ValueIsInvalidAccessor;
            ValueMustBeANumberAccessor       = originalProvider.ValueMustBeANumberAccessor;
        }
Пример #3
0
        private DefaultModelMetadataProvider(
            ICompositeMetadataDetailsProvider detailsProvider,
            ModelBindingMessageProvider modelBindingMessageProvider)
        {
            if (detailsProvider == null)
            {
                throw new ArgumentNullException(nameof(detailsProvider));
            }

            DetailsProvider             = detailsProvider;
            ModelBindingMessageProvider = modelBindingMessageProvider;

            _cacheEntryFactory = CreateCacheEntry;
            _metadataCacheEntryForObjectType = GetMetadataCacheEntryForObjectType();
        }