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.
Add
[ValidateNever]
and IPropertyValidationFilter
- #5642 - lazy-load `ValidationEntry.Model` - avoids `Exception`s when moving to a property that will not be validated nits: - remove duplicate code in `ValidationVisitor` - clarify "all properties of" doc comments - also add missing `<param>` doc in `ViewDataInfo`
- Loading branch information
Showing
19 changed files
with
792 additions
and
88 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
22 changes: 22 additions & 0 deletions
22
...icrosoft.AspNetCore.Mvc.Abstractions/ModelBinding/Validation/IPropertyValidationFilter.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,22 @@ | ||
// 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. | ||
|
||
namespace Microsoft.AspNetCore.Mvc.ModelBinding.Validation | ||
{ | ||
/// <summary> | ||
/// Contract for attributes that determine whether associated properties should be validated. When the attribute is | ||
/// applied to a property, the validation system calls <see cref="ShouldValidateEntry"/> to determine whether to | ||
/// validate that property. When applied to a type, the validation system calls <see cref="ShouldValidateEntry"/> | ||
/// for each property that type defines to determine whether to validate it. | ||
/// </summary> | ||
public interface IPropertyValidationFilter | ||
{ | ||
/// <summary> | ||
/// Gets an indication whether the <paramref name="entry"/> should be validated. | ||
/// </summary> | ||
/// <param name="entry"><see cref="ValidationEntry"/> to check.</param> | ||
/// <param name="parentEntry"><see cref="ValidationEntry"/> containing <paramref name="entry"/>.</param> | ||
/// <returns><c>true</c> if <paramref name="entry"/> should be validated; <c>false</c> otherwise.</returns> | ||
bool ShouldValidateEntry(ValidationEntry entry, ValidationEntry parentEntry); | ||
} | ||
} |
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
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
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
22 changes: 22 additions & 0 deletions
22
src/Microsoft.AspNetCore.Mvc.Core/ModelBinding/Validation/ValidateNeverAttribute.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,22 @@ | ||
// 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.AspNetCore.Mvc.ModelBinding.Validation | ||
{ | ||
/// <summary> | ||
/// <see cref="IPropertyValidationFilter"/> implementation that unconditionally indicates a property should be | ||
/// excluded from validation. When applied to a property, the validation system excludes that property. When | ||
/// applied to a type, the validation system excludes all properties within that type. | ||
/// </summary> | ||
[AttributeUsage(AttributeTargets.Class | AttributeTargets.Property, AllowMultiple = false, Inherited = true)] | ||
public sealed class ValidateNeverAttribute : Attribute, IPropertyValidationFilter | ||
{ | ||
/// <inheritdoc /> | ||
public bool ShouldValidateEntry(ValidationEntry entry, ValidationEntry parentEntry) | ||
{ | ||
return false; | ||
} | ||
} | ||
} |
Oops, something went wrong.