You've already forked linux-packaging-mono
Imported Upstream version 5.10.0.69
Former-commit-id: fc39669a0b707dd3c063977486506b6793da2890
This commit is contained in:
parent
d8f8abd549
commit
e2950ec768
@@ -81,7 +81,7 @@ namespace System.ComponentModel.DataAnnotations
|
||||
public virtual string GetDataTypeName() { throw null; }
|
||||
public override bool IsValid(object value) { throw null; }
|
||||
}
|
||||
[System.AttributeUsageAttribute((System.AttributeTargets)(2496), AllowMultiple = false)]
|
||||
[System.AttributeUsageAttribute(AttributeTargets.Property | AttributeTargets.Field | AttributeTargets.Parameter | AttributeTargets.Method | AttributeTargets.Class, AllowMultiple = false)]
|
||||
public sealed partial class DisplayAttribute : System.Attribute
|
||||
{
|
||||
public DisplayAttribute() { }
|
||||
|
||||
@@ -0,0 +1,12 @@
|
||||
<Directives xmlns="http://schemas.microsoft.com/netfx/2013/01/metadata">
|
||||
<Library Name="System.ComponentModel.Annotations">
|
||||
<Namespace Name="System.ComponentModel.DataAnnotations" Dynamic="Required All" />
|
||||
<Assembly Name="System.ComponentModel.Annotations">
|
||||
<Type Name="System.ComponentModel.DataAnnotations.ValidationAttribute">
|
||||
<Method Name="GetValidationResult">
|
||||
<Parameter Name="value" Dynamic="Required All"/>
|
||||
</Method>
|
||||
</Type>
|
||||
</Assembly>
|
||||
</Library>
|
||||
</Directives>
|
||||
@@ -64,5 +64,8 @@
|
||||
<Reference Include="mscorlib" />
|
||||
<Reference Include="System.ComponentModel.DataAnnotations" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<EmbeddedResource Include="Resources\$(AssemblyName).rd.xml" />
|
||||
</ItemGroup>
|
||||
<Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.targets))\dir.targets" />
|
||||
</Project>
|
||||
@@ -23,8 +23,7 @@ namespace System.ComponentModel.DataAnnotations
|
||||
return true;
|
||||
}
|
||||
|
||||
var ccValue = value as string;
|
||||
if (ccValue == null)
|
||||
if (!(value is string ccValue))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -12,7 +12,7 @@ namespace System.ComponentModel.DataAnnotations
|
||||
/// <see cref="ResourceType" />
|
||||
/// </summary>
|
||||
[AttributeUsage(
|
||||
AttributeTargets.Property | AttributeTargets.Field | AttributeTargets.Parameter | AttributeTargets.Method,
|
||||
AttributeTargets.Property | AttributeTargets.Field | AttributeTargets.Parameter | AttributeTargets.Method | AttributeTargets.Class,
|
||||
AllowMultiple = false)]
|
||||
public sealed class DisplayAttribute : Attribute
|
||||
{
|
||||
|
||||
@@ -23,8 +23,7 @@ namespace System.ComponentModel.DataAnnotations
|
||||
return true;
|
||||
}
|
||||
|
||||
var valueAsString = value as string;
|
||||
if (valueAsString == null)
|
||||
if (!(value is string valueAsString))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -38,7 +38,7 @@ namespace System.ComponentModel.DataAnnotations
|
||||
return true;
|
||||
}
|
||||
var stringValue = value as string;
|
||||
if (stringValue != null && string.IsNullOrEmpty(stringValue))
|
||||
if (stringValue?.Length == 0)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
@@ -76,14 +76,9 @@ namespace System.ComponentModel.DataAnnotations
|
||||
{
|
||||
try
|
||||
{
|
||||
if (stringValue != null)
|
||||
{
|
||||
convertedValue = Enum.Parse(EnumType, stringValue, false);
|
||||
}
|
||||
else
|
||||
{
|
||||
convertedValue = Enum.ToObject(EnumType, value);
|
||||
}
|
||||
convertedValue = stringValue != null
|
||||
? Enum.Parse(EnumType, stringValue, false)
|
||||
: Enum.ToObject(EnumType, value);
|
||||
}
|
||||
catch (ArgumentException)
|
||||
{
|
||||
|
||||
@@ -43,21 +43,8 @@ namespace System.ComponentModel.DataAnnotations
|
||||
public override string FormatErrorMessage(string name) =>
|
||||
string.Format(CultureInfo.CurrentCulture, ErrorMessageString, name, ExtensionsFormatted);
|
||||
|
||||
public override bool IsValid(object value)
|
||||
{
|
||||
if (value == null)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
var valueAsString = value as string;
|
||||
if (valueAsString != null)
|
||||
{
|
||||
return ValidateExtension(valueAsString);
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
public override bool IsValid(object value) =>
|
||||
value == null || value is string valueAsString && ValidateExtension(valueAsString);
|
||||
|
||||
private bool ValidateExtension(string fileName)
|
||||
{
|
||||
|
||||
@@ -83,15 +83,7 @@ namespace System.ComponentModel.DataAnnotations
|
||||
/// <param name="obj">An System.Object.</param>
|
||||
/// <returns>true if obj is a FilterUIHintAttribute and its value is the same
|
||||
/// as this instance; otherwise, false.</returns>
|
||||
public override bool Equals(object obj)
|
||||
{
|
||||
var otherAttribute = obj as FilterUIHintAttribute;
|
||||
if (otherAttribute == null)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
return _implementation.Equals(otherAttribute._implementation);
|
||||
}
|
||||
public override bool Equals(object obj) =>
|
||||
obj is FilterUIHintAttribute otherAttribute && _implementation.Equals(otherAttribute._implementation);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -65,7 +65,7 @@ namespace System.ComponentModel.DataAnnotations
|
||||
// Check the lengths for legality
|
||||
EnsureLegalLengths();
|
||||
|
||||
var length = 0;
|
||||
int length;
|
||||
// Automatically pass if value is null. RequiredAttribute should be used to assert a value is not null.
|
||||
if (value == null)
|
||||
{
|
||||
|
||||
@@ -49,7 +49,7 @@ namespace System.ComponentModel.DataAnnotations
|
||||
// Check the lengths for legality
|
||||
EnsureLegalLengths();
|
||||
|
||||
var length = 0;
|
||||
int length;
|
||||
// Automatically pass if value is null. RequiredAttribute should be used to assert a value is not null.
|
||||
if (value == null)
|
||||
{
|
||||
|
||||
@@ -8,10 +8,10 @@ namespace System.ComponentModel.DataAnnotations
|
||||
AllowMultiple = false)]
|
||||
public sealed class PhoneAttribute : DataTypeAttribute
|
||||
{
|
||||
private const string _additionalPhoneNumberCharacters = "-.()";
|
||||
private const string _extensionAbbreviationExtDot = "ext.";
|
||||
private const string _extensionAbbreviationExt = "ext";
|
||||
private const string _extensionAbbreviationX = "x";
|
||||
private const string AdditionalPhoneNumberCharacters = "-.()";
|
||||
private const string ExtensionAbbreviationExtDot = "ext.";
|
||||
private const string ExtensionAbbreviationExt = "ext";
|
||||
private const string ExtensionAbbreviationX = "x";
|
||||
|
||||
public PhoneAttribute()
|
||||
: base(DataType.PhoneNumber)
|
||||
@@ -28,8 +28,7 @@ namespace System.ComponentModel.DataAnnotations
|
||||
return true;
|
||||
}
|
||||
|
||||
var valueAsString = value as string;
|
||||
if (valueAsString == null)
|
||||
if (!(value is string valueAsString))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
@@ -56,7 +55,7 @@ namespace System.ComponentModel.DataAnnotations
|
||||
{
|
||||
if (!(Char.IsDigit(c)
|
||||
|| Char.IsWhiteSpace(c)
|
||||
|| _additionalPhoneNumberCharacters.IndexOf(c) != -1))
|
||||
|| AdditionalPhoneNumberCharacters.IndexOf(c) != -1))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
@@ -68,11 +67,11 @@ namespace System.ComponentModel.DataAnnotations
|
||||
private static string RemoveExtension(string potentialPhoneNumber)
|
||||
{
|
||||
var lastIndexOfExtension = potentialPhoneNumber
|
||||
.LastIndexOf(_extensionAbbreviationExtDot, StringComparison.OrdinalIgnoreCase);
|
||||
.LastIndexOf(ExtensionAbbreviationExtDot, StringComparison.OrdinalIgnoreCase);
|
||||
if (lastIndexOfExtension >= 0)
|
||||
{
|
||||
var extension = potentialPhoneNumber.Substring(
|
||||
lastIndexOfExtension + _extensionAbbreviationExtDot.Length);
|
||||
lastIndexOfExtension + ExtensionAbbreviationExtDot.Length);
|
||||
if (MatchesExtension(extension))
|
||||
{
|
||||
return potentialPhoneNumber.Substring(0, lastIndexOfExtension);
|
||||
@@ -80,11 +79,11 @@ namespace System.ComponentModel.DataAnnotations
|
||||
}
|
||||
|
||||
lastIndexOfExtension = potentialPhoneNumber
|
||||
.LastIndexOf(_extensionAbbreviationExt, StringComparison.OrdinalIgnoreCase);
|
||||
.LastIndexOf(ExtensionAbbreviationExt, StringComparison.OrdinalIgnoreCase);
|
||||
if (lastIndexOfExtension >= 0)
|
||||
{
|
||||
var extension = potentialPhoneNumber.Substring(
|
||||
lastIndexOfExtension + _extensionAbbreviationExt.Length);
|
||||
lastIndexOfExtension + ExtensionAbbreviationExt.Length);
|
||||
if (MatchesExtension(extension))
|
||||
{
|
||||
return potentialPhoneNumber.Substring(0, lastIndexOfExtension);
|
||||
@@ -92,11 +91,11 @@ namespace System.ComponentModel.DataAnnotations
|
||||
}
|
||||
|
||||
lastIndexOfExtension = potentialPhoneNumber
|
||||
.LastIndexOf(_extensionAbbreviationX, StringComparison.OrdinalIgnoreCase);
|
||||
.LastIndexOf(ExtensionAbbreviationX, StringComparison.OrdinalIgnoreCase);
|
||||
if (lastIndexOfExtension >= 0)
|
||||
{
|
||||
var extension = potentialPhoneNumber.Substring(
|
||||
lastIndexOfExtension + _extensionAbbreviationX.Length);
|
||||
lastIndexOfExtension + ExtensionAbbreviationX.Length);
|
||||
if (MatchesExtension(extension))
|
||||
{
|
||||
return potentialPhoneNumber.Substring(0, lastIndexOfExtension);
|
||||
|
||||
@@ -98,17 +98,12 @@ namespace System.ComponentModel.DataAnnotations
|
||||
SetupConversion();
|
||||
|
||||
// Automatically pass if value is null or empty. RequiredAttribute should be used to assert a value is not empty.
|
||||
if (value == null)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
var s = value as string;
|
||||
if (s != null && string.IsNullOrEmpty(s))
|
||||
if (value == null || (value as string)?.Length == 0)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
object convertedValue = null;
|
||||
object convertedValue;
|
||||
|
||||
try
|
||||
{
|
||||
|
||||
@@ -103,7 +103,7 @@ namespace System.ComponentModel.DataAnnotations
|
||||
|
||||
Regex = MatchTimeoutInMilliseconds == -1
|
||||
? new Regex(Pattern)
|
||||
: new Regex(Pattern, default(RegexOptions), TimeSpan.FromMilliseconds((double)MatchTimeoutInMilliseconds));
|
||||
: new Regex(Pattern, default(RegexOptions), TimeSpan.FromMilliseconds(MatchTimeoutInMilliseconds));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -45,13 +45,7 @@ namespace System.ComponentModel.DataAnnotations
|
||||
}
|
||||
|
||||
// only check string length if empty strings are not allowed
|
||||
var stringValue = value as string;
|
||||
if (stringValue != null && !AllowEmptyStrings)
|
||||
{
|
||||
return stringValue.Trim().Length != 0;
|
||||
}
|
||||
|
||||
return true;
|
||||
return AllowEmptyStrings || !(value is string stringValue) || stringValue.Trim().Length != 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -50,8 +50,13 @@ namespace System.ComponentModel.DataAnnotations
|
||||
|
||||
// Automatically pass if value is null. RequiredAttribute should be used to assert a value is not null.
|
||||
// We expect a cast exception if a non-string was passed in.
|
||||
var length = value == null ? 0 : ((string)value).Length;
|
||||
return value == null || (length >= MinimumLength && length <= MaximumLength);
|
||||
if (value == null)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
int length = ((string)value).Length;
|
||||
return length >= MinimumLength && length <= MaximumLength;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
||||
@@ -66,15 +66,8 @@ namespace System.ComponentModel.DataAnnotations
|
||||
|
||||
public override int GetHashCode() => _implementation.GetHashCode();
|
||||
|
||||
public override bool Equals(object obj)
|
||||
{
|
||||
var otherAttribute = obj as UIHintAttribute;
|
||||
if (otherAttribute == null)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
return _implementation.Equals(otherAttribute._implementation);
|
||||
}
|
||||
public override bool Equals(object obj) =>
|
||||
obj is UIHintAttribute otherAttribute && _implementation.Equals(otherAttribute._implementation);
|
||||
|
||||
internal class UIHintImplementation
|
||||
{
|
||||
@@ -102,20 +95,11 @@ namespace System.ComponentModel.DataAnnotations
|
||||
/// </summary>
|
||||
public string PresentationLayer { get; }
|
||||
|
||||
public IDictionary<string, object> ControlParameters
|
||||
{
|
||||
get
|
||||
{
|
||||
if (_controlParameters == null)
|
||||
{
|
||||
// Lazy load the dictionary. It's fine if this method executes multiple times in stress scenarios.
|
||||
// If the method throws (indicating that the input params are invalid) this property will throw
|
||||
// every time it's accessed.
|
||||
_controlParameters = BuildControlParametersDictionary();
|
||||
}
|
||||
return _controlParameters;
|
||||
}
|
||||
}
|
||||
// Lazy load the dictionary. It's fine if this method executes multiple times in stress scenarios.
|
||||
// If the method throws (indicating that the input params are invalid) this property will throw
|
||||
// every time it's accessed.
|
||||
public IDictionary<string, object> ControlParameters =>
|
||||
_controlParameters ?? (_controlParameters = BuildControlParametersDictionary());
|
||||
|
||||
/// <summary>
|
||||
/// Returns the hash code for this UIHintAttribute.
|
||||
@@ -203,8 +187,7 @@ namespace System.ComponentModel.DataAnnotations
|
||||
i));
|
||||
}
|
||||
|
||||
var keyString = key as string;
|
||||
if (keyString == null)
|
||||
if (!(key is string keyString))
|
||||
{
|
||||
throw new InvalidOperationException(
|
||||
string.Format(
|
||||
|
||||
@@ -23,8 +23,7 @@ namespace System.ComponentModel.DataAnnotations
|
||||
return true;
|
||||
}
|
||||
|
||||
var valueAsString = value as string;
|
||||
return valueAsString != null &&
|
||||
return value is string valueAsString &&
|
||||
(valueAsString.StartsWith("http://", StringComparison.OrdinalIgnoreCase)
|
||||
|| valueAsString.StartsWith("https://", StringComparison.OrdinalIgnoreCase)
|
||||
|| valueAsString.StartsWith("ftp://", StringComparison.OrdinalIgnoreCase));
|
||||
|
||||
@@ -231,11 +231,8 @@ namespace System.ComponentModel.DataAnnotations
|
||||
{
|
||||
// Here if not using resource type/name -- the accessor is just the error message string,
|
||||
// which we know is not empty to have gotten this far.
|
||||
_errorMessageResourceAccessor = delegate
|
||||
{
|
||||
// We captured error message to local in case it changes before accessor runs
|
||||
return localErrorMessage;
|
||||
};
|
||||
// We captured error message to local in case it changes before accessor runs
|
||||
_errorMessageResourceAccessor = () => localErrorMessage;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -283,7 +280,7 @@ namespace System.ComponentModel.DataAnnotations
|
||||
_errorMessageResourceType.FullName));
|
||||
}
|
||||
|
||||
_errorMessageResourceAccessor = delegate { return (string)property.GetValue(null, null); };
|
||||
_errorMessageResourceAccessor = () => (string)property.GetValue(null, null);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
@@ -116,14 +116,14 @@ namespace System.ComponentModel.DataAnnotations
|
||||
|
||||
lock (_typeStoreItems)
|
||||
{
|
||||
TypeStoreItem item = null;
|
||||
if (!_typeStoreItems.TryGetValue(type, out item))
|
||||
if (!_typeStoreItems.TryGetValue(type, out TypeStoreItem item))
|
||||
{
|
||||
// use CustomAttributeExtensions.GetCustomAttributes() to get inherited attributes as well as direct ones
|
||||
var attributes = CustomAttributeExtensions.GetCustomAttributes(type, true);
|
||||
item = new TypeStoreItem(type, attributes);
|
||||
_typeStoreItems[type] = item;
|
||||
}
|
||||
|
||||
return item;
|
||||
}
|
||||
}
|
||||
@@ -179,14 +179,13 @@ namespace System.ComponentModel.DataAnnotations
|
||||
|
||||
internal PropertyStoreItem GetPropertyStoreItem(string propertyName)
|
||||
{
|
||||
PropertyStoreItem item = null;
|
||||
if (!TryGetPropertyStoreItem(propertyName, out item))
|
||||
if (!TryGetPropertyStoreItem(propertyName, out PropertyStoreItem item))
|
||||
{
|
||||
throw new ArgumentException(
|
||||
string.Format(CultureInfo.CurrentCulture,
|
||||
SR.AttributeStore_Unknown_Property, _type.Name, propertyName),
|
||||
nameof(propertyName));
|
||||
SR.AttributeStore_Unknown_Property, _type.Name, propertyName), nameof(propertyName));
|
||||
}
|
||||
|
||||
return item;
|
||||
}
|
||||
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user