Imported Upstream version 5.16.0.100

Former-commit-id: 38faa55fb9669e35e7d8448b15c25dc447f25767
This commit is contained in:
Xamarin Public Jenkins (auto-signing)
2018-08-07 15:19:03 +00:00
parent 0a9828183b
commit 7d7f676260
4419 changed files with 170950 additions and 90273 deletions

View File

@@ -16,7 +16,7 @@
<FrameworkReference>System.ComponentModel.DataAnnotations</FrameworkReference>
</InboxOnTargetFramework>
<InboxOnTargetFramework Include="netcoreapp2.0" />
<InboxOnTargetFramework Include="$(UAPvNextTFM)" />
<InboxOnTargetFramework Include="uap10.0.16299" />
<InboxOnTargetFramework Include="win8" />
<InboxOnTargetFramework Include="portable-net45+win8" />
<InboxOnTargetFramework Include="xamarinios10" />

View File

@@ -204,9 +204,11 @@ namespace System.ComponentModel.DataAnnotations
public RangeAttribute(double minimum, double maximum) { }
public RangeAttribute(int minimum, int maximum) { }
public RangeAttribute(System.Type type, string minimum, string maximum) { }
public bool ConvertValueInInvariantCulture { get { throw null; } set { } }
public object Maximum { get { throw null; } }
public object Minimum { get { throw null; } }
public System.Type OperandType { get { throw null; } }
public bool ParseLimitsInInvariantCulture { get { throw null; } set { } }
public override string FormatErrorMessage(string name) { throw null; }
public override bool IsValid(object value) { throw null; }
}

View File

@@ -70,6 +70,21 @@ namespace System.ComponentModel.DataAnnotations
/// </summary>
public Type OperandType { get; }
/// <summary>
/// Determines whether string values for <see cref="Minimum"/> and <see cref="Maximum"/> are parsed in the invariant
/// culture rather than the current culture in effect at the time of the validation.
/// </summary>
public bool ParseLimitsInInvariantCulture { get; set; }
/// <summary>
/// Determines whether any conversions necessary from the value being validated to <see cref="OperandType"/> as set
/// by the <c>type</c> parameter of the <see cref="RangeAttribute(Type, string, string)"/> constructor are carried
/// out in the invariant culture rather than the current culture in effect at the time of the validation.
/// </summary>
/// <remarks>This property has no effects with the constructors with <see cref="int"/> or <see cref="double"/>
/// parameters, for which the invariant culture is always used for any conversions of the validated value.</remarks>
public bool ConvertValueInInvariantCulture { get; set; }
private Func<object, object> Conversion { get; set; }
private void Initialize(IComparable minimum, IComparable maximum, Func<object, object> conversion)
@@ -192,10 +207,25 @@ namespace System.ComponentModel.DataAnnotations
}
TypeConverter converter = TypeDescriptor.GetConverter(type);
IComparable min = (IComparable)converter.ConvertFromString((string)minimum);
IComparable max = (IComparable)converter.ConvertFromString((string)maximum);
IComparable min = (IComparable)(ParseLimitsInInvariantCulture
? converter.ConvertFromInvariantString((string)minimum)
: converter.ConvertFromString((string)minimum));
IComparable max = (IComparable)(ParseLimitsInInvariantCulture
? converter.ConvertFromInvariantString((string)maximum)
: converter.ConvertFromString((string)maximum));
Func<object, object> conversion;
if (ConvertValueInInvariantCulture)
{
conversion = value => value?.GetType() == type
? value
: converter.ConvertFrom(null, CultureInfo.InvariantCulture, value);
}
else
{
conversion = value => value?.GetType() == type ? value : converter.ConvertFrom(value);
}
Func<object, object> conversion = value => (value != null && value.GetType() == type) ? value : converter.ConvertFrom(value);
Initialize(min, max, conversion);
}
}

View File

@@ -229,7 +229,7 @@ namespace System.ComponentModel.DataAnnotations.Tests
var results = new List<ValidationResult>();
Assert.False(Validator.TryValidateObject(instance, context, results));
Assert.Equal("The Required field is required.", Assert.Single(results).ErrorMessage);
Assert.Contains("Required", Assert.Single(results).ErrorMessage);
}
public class RequiredFailure