// Copyright (c) Microsoft Open Technologies, Inc. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using Microsoft.Framework.Internal; namespace Microsoft.AspNet.Mvc.ModelBinding.Validation { public class ModelValidationContext { public ModelValidationContext( [NotNull] ModelBindingContext bindingContext, [NotNull] ModelExplorer modelExplorer) : this(bindingContext.ModelName, bindingContext.BindingSource, bindingContext.OperationBindingContext.ValidatorProvider, bindingContext.ModelState, modelExplorer) { } public ModelValidationContext( string rootPrefix, BindingSource bindingSource, [NotNull] IModelValidatorProvider validatorProvider, [NotNull] ModelStateDictionary modelState, [NotNull] ModelExplorer modelExplorer) { ModelState = modelState; RootPrefix = rootPrefix; ValidatorProvider = validatorProvider; ModelExplorer = modelExplorer; BindingSource = bindingSource; } /// /// Constructs a new instance of the class using the /// and . /// /// Existing . /// associated with the new /// . /// public static ModelValidationContext GetChildValidationContext( [NotNull] ModelValidationContext parentContext, [NotNull] ModelExplorer modelExplorer) { return new ModelValidationContext( parentContext.RootPrefix, modelExplorer.Metadata.BindingSource, parentContext.ValidatorProvider, parentContext.ModelState, modelExplorer); } public ModelExplorer ModelExplorer { get; } public ModelStateDictionary ModelState { get; } public string RootPrefix { get; set; } public BindingSource BindingSource { get; set; } public IModelValidatorProvider ValidatorProvider { get; } } }