@@ -30,7 +30,7 @@ public class ModelStateDictionary : IReadOnlyDictionary<string, ModelStateEntry>
30
30
31
31
private readonly ModelStateNode _root ;
32
32
private int _maxAllowedErrors ;
33
- private int _maxRecursionDepth ;
33
+ private int ? _maxValidationDepth ;
34
34
35
35
/// <summary>
36
36
/// Initializes a new instance of the <see cref="ModelStateDictionary"/> class.
@@ -44,9 +44,17 @@ public ModelStateDictionary()
44
44
/// Initializes a new instance of the <see cref="ModelStateDictionary"/> class.
45
45
/// </summary>
46
46
public ModelStateDictionary ( int maxAllowedErrors )
47
+ : this ( maxAllowedErrors , DefaultMaxRecursionDepth )
48
+ {
49
+ }
50
+
51
+ /// <summary>
52
+ /// Initializes a new instance of the <see cref="ModelStateDictionary"/> class.
53
+ /// </summary>
54
+ private ModelStateDictionary ( int maxAllowedErrors , int maxValidationDepth )
47
55
{
48
56
MaxAllowedErrors = maxAllowedErrors ;
49
- MaxRecursionDepth = DefaultMaxRecursionDepth ;
57
+ MaxValidationDepth = maxValidationDepth ;
50
58
var emptySegment = new StringSegment ( buffer : string . Empty ) ;
51
59
_root = new ModelStateNode ( subKey : emptySegment )
52
60
{
@@ -60,7 +68,7 @@ public ModelStateDictionary(int maxAllowedErrors)
60
68
/// </summary>
61
69
/// <param name="dictionary">The <see cref="ModelStateDictionary"/> to copy values from.</param>
62
70
public ModelStateDictionary ( ModelStateDictionary dictionary )
63
- : this ( dictionary ? . MaxAllowedErrors ?? DefaultMaxAllowedErrors )
71
+ : this ( dictionary ? . MaxAllowedErrors ?? DefaultMaxAllowedErrors , dictionary ? . MaxValidationDepth ?? DefaultMaxRecursionDepth )
64
72
{
65
73
if ( dictionary == null )
66
74
{
@@ -176,19 +184,19 @@ public ModelStateEntry this[string key]
176
184
// Flag that indicates if TooManyModelErrorException has already been added to this dictionary.
177
185
private bool HasRecordedMaxModelError { get ; set ; }
178
186
179
- internal int MaxRecursionDepth
187
+ internal int ? MaxValidationDepth
180
188
{
181
189
get
182
190
{
183
- return _maxRecursionDepth ;
191
+ return _maxValidationDepth ;
184
192
}
185
193
set
186
194
{
187
195
if ( value < 0 )
188
196
{
189
197
throw new ArgumentOutOfRangeException ( nameof ( value ) ) ;
190
198
}
191
- _maxRecursionDepth = value ;
199
+ _maxValidationDepth = value ;
192
200
}
193
201
}
194
202
@@ -682,7 +690,8 @@ private static StringSegment FindNext(string key, ref MatchResult currentMatch)
682
690
683
691
private ModelValidationState ? GetValidity ( ModelStateNode node , int currentDepth )
684
692
{
685
- if ( node == null || currentDepth >= MaxRecursionDepth )
693
+ if ( node == null ||
694
+ ( MaxValidationDepth != null && currentDepth >= MaxValidationDepth ) )
686
695
{
687
696
return null ;
688
697
}
0 commit comments