This repository has been archived by the owner on Dec 14, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
64 changed files
with
2,895 additions
and
1,659 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
76 changes: 0 additions & 76 deletions
76
src/Microsoft.AspNet.Mvc.Abstractions/ModelBinding/ModelValidationNode.cs
This file was deleted.
Oops, something went wrong.
23 changes: 23 additions & 0 deletions
23
src/Microsoft.AspNet.Mvc.Abstractions/ModelBinding/Validation/IValidationStrategy.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
// Copyright (c) .NET Foundation. All rights reserved. | ||
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. | ||
|
||
using System.Collections.Generic; | ||
|
||
namespace Microsoft.AspNet.Mvc.ModelBinding.Validation | ||
{ | ||
/// <summary> | ||
/// Defines a strategy for enumerating the child entries of a model object which should be validated. | ||
/// </summary> | ||
public interface IValidationStrategy | ||
{ | ||
/// <summary> | ||
/// Gets an <see cref="IEnumerator{ValidationEntry}"/> containing a <see cref="ValidationEntry"/> for | ||
/// each child entry of the model object to be validated. | ||
/// </summary> | ||
/// <param name="metadata">The <see cref="ModelMetadata"/> associated with <paramref name="model"/>.</param> | ||
/// <param name="key">The model prefix associated with <paramref name="model"/>.</param> | ||
/// <param name="model">The model object.</param> | ||
/// <returns>An <see cref="IEnumerator{ValidationEntry}"/>.</returns> | ||
IEnumerator<ValidationEntry> GetChildren(ModelMetadata metadata, string key, object model); | ||
} | ||
} |
64 changes: 13 additions & 51 deletions
64
src/Microsoft.AspNet.Mvc.Abstractions/ModelBinding/Validation/ModelValidationContext.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,64 +1,26 @@ | ||
// Copyright (c) .NET Foundation. 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 | ||
{ | ||
/// <summary> | ||
/// A context object for <see cref="IModelValidator"/>. | ||
/// </summary> | ||
public class ModelValidationContext | ||
{ | ||
public ModelValidationContext( | ||
[NotNull] ModelBindingContext bindingContext, | ||
[NotNull] ModelExplorer modelExplorer) | ||
: this( | ||
bindingContext.BindingSource, | ||
bindingContext.OperationBindingContext.ValidatorProvider, | ||
bindingContext.ModelState, | ||
modelExplorer) | ||
{ | ||
} | ||
|
||
public ModelValidationContext( | ||
BindingSource bindingSource, | ||
[NotNull] IModelValidatorProvider validatorProvider, | ||
[NotNull] ModelStateDictionary modelState, | ||
[NotNull] ModelExplorer modelExplorer) | ||
{ | ||
ModelState = modelState; | ||
ValidatorProvider = validatorProvider; | ||
ModelExplorer = modelExplorer; | ||
BindingSource = bindingSource; | ||
} | ||
|
||
/// <summary> | ||
/// Constructs a new instance of the <see cref="ModelValidationContext"/> class using the | ||
/// <paramref name="parentContext" /> and <paramref name="modelExplorer"/>. | ||
/// Gets or sets the model object. | ||
/// </summary> | ||
/// <param name="parentContext">Existing <see cref="ModelValidationContext"/>.</param> | ||
/// <param name="modelExplorer"> | ||
/// <see cref="ModelExplorer"/> associated with the new <see cref="ModelValidationContext"/>. | ||
/// </param> | ||
/// <returns> | ||
/// A new instance of the <see cref="ModelValidationContext"/> class using the | ||
/// <paramref name="parentContext" /> and <paramref name="modelExplorer"/>. | ||
/// </returns> | ||
public static ModelValidationContext GetChildValidationContext( | ||
[NotNull] ModelValidationContext parentContext, | ||
[NotNull] ModelExplorer modelExplorer) | ||
{ | ||
return new ModelValidationContext( | ||
modelExplorer.Metadata.BindingSource, | ||
parentContext.ValidatorProvider, | ||
parentContext.ModelState, | ||
modelExplorer); | ||
} | ||
|
||
public ModelExplorer ModelExplorer { get; } | ||
|
||
public ModelStateDictionary ModelState { get; } | ||
public object Model { get; set; } | ||
|
||
public BindingSource BindingSource { get; set; } | ||
/// <summary> | ||
/// Gets or sets the model container object. | ||
/// </summary> | ||
public object Container { get; set; } | ||
|
||
public IModelValidatorProvider ValidatorProvider { get; } | ||
/// <summary> | ||
/// Gets or sets the <see cref="ModelMetadata"/> associated with <see cref="Model"/>. | ||
/// </summary> | ||
public ModelMetadata Metadata { get; set; } | ||
} | ||
} |
51 changes: 51 additions & 0 deletions
51
src/Microsoft.AspNet.Mvc.Abstractions/ModelBinding/Validation/ValidationEntry.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
// Copyright (c) .NET Foundation. All rights reserved. | ||
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. | ||
|
||
using System; | ||
|
||
namespace Microsoft.AspNet.Mvc.ModelBinding.Validation | ||
{ | ||
/// <summary> | ||
/// Contains data needed for validating a child entry of a model object. See <see cref="IValidationStrategy"/>. | ||
/// </summary> | ||
public struct ValidationEntry | ||
{ | ||
/// <summary> | ||
/// Creates a new <see cref="ValidationEntry"/>. | ||
/// </summary> | ||
/// <param name="metadata">The <see cref="ModelMetadata"/> associated with <paramref name="model"/>.</param> | ||
/// <param name="key">The model prefix associated with <paramref name="model"/>.</param> | ||
/// <param name="model">The model object.</param> | ||
public ValidationEntry(ModelMetadata metadata, string key, object model) | ||
{ | ||
if (metadata == null) | ||
{ | ||
throw new ArgumentNullException(nameof(metadata)); | ||
} | ||
|
||
if (key == null) | ||
{ | ||
throw new ArgumentNullException(nameof(key)); | ||
} | ||
|
||
Metadata = metadata; | ||
Key = key; | ||
Model = model; | ||
} | ||
|
||
/// <summary> | ||
/// The model prefix associated with <see cref="Model"/>. | ||
/// </summary> | ||
public string Key { get; } | ||
|
||
/// <summary> | ||
/// The <see cref="ModelMetadata"/> associated with <see cref="Model"/>. | ||
/// </summary> | ||
public ModelMetadata Metadata { get; } | ||
|
||
/// <summary> | ||
/// The model object. | ||
/// </summary> | ||
public object Model { get; } | ||
} | ||
} |
Oops, something went wrong.