Imported Upstream version 4.8.0.309

Former-commit-id: 5f9c6ae75f295e057a7d2971f3a6df4656fa8850
This commit is contained in:
Xamarin Public Jenkins (auto-signing)
2016-11-10 13:04:39 +00:00
parent ee1447783b
commit 94b2861243
4912 changed files with 390737 additions and 49310 deletions

View File

@@ -21,8 +21,10 @@ namespace System.ComponentModel.DataAnnotations {
}
public static void SetDefaultsLessOrEqual_46() {
#pragma warning disable BCL0012 //disable warning about AppContextDefaults not following the recommended pattern
// Define the switches that should be true for 4.6 or less, false for 4.6.1+.
LocalAppContext.DefineSwitchDefault(UseLegacyRegExTimeoutString, true);
#pragma warning restore BCL0012
}
}
}

View File

@@ -1,4 +1,4 @@
using System.ComponentModel.DataAnnotations.Resources;
using System.ComponentModel.DataAnnotations.Resources;
using System.Diagnostics.CodeAnalysis;
using System.Globalization;
using System.Text.RegularExpressions;
@@ -19,7 +19,18 @@ namespace System.ComponentModel.DataAnnotations {
/// Gets or sets the timeout to use when matching the regular expression pattern (in milliseconds)
/// (-1 means never timeout).
/// </summary>
public int MatchTimeoutInMilliseconds { get; set; } = GetDefaultTimeout();
public int MatchTimeoutInMilliseconds {
get {
return _matchTimeoutInMilliseconds;
}
set {
_matchTimeoutInMilliseconds = value;
_matchTimeoutSet = true;
}
}
private int _matchTimeoutInMilliseconds;
private bool _matchTimeoutSet;
private Regex Regex { get; set; }
@@ -90,6 +101,11 @@ namespace System.ComponentModel.DataAnnotations {
if (string.IsNullOrEmpty(this.Pattern)) {
throw new InvalidOperationException(DataAnnotationsResources.RegularExpressionAttribute_Empty_Pattern);
}
if (!_matchTimeoutSet) {
MatchTimeoutInMilliseconds = GetDefaultTimeout();
}
Regex = MatchTimeoutInMilliseconds == -1
? new Regex(Pattern)
: Regex = new Regex(Pattern, default(RegexOptions), TimeSpan.FromMilliseconds((double)MatchTimeoutInMilliseconds));