You've already forked linux-packaging-mono
Imported Upstream version 5.10.0.47
Former-commit-id: d0813289fa2d35e1f8ed77530acb4fb1df441bc0
This commit is contained in:
parent
88ff76fe28
commit
e46a49ecf1
@@ -3,7 +3,7 @@
|
||||
<Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.props))\dir.props" />
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\ref\System.ComponentModel.Annotations.csproj">
|
||||
<SupportedFramework>net461;netcoreapp2.0;$(AllXamarinFrameworks)</SupportedFramework>
|
||||
<SupportedFramework>net461;netcoreapp2.1;$(AllXamarinFrameworks)</SupportedFramework>
|
||||
</ProjectReference>
|
||||
<ProjectReference Include="..\src\System.ComponentModel.Annotations.csproj" />
|
||||
<HarvestIncludePaths Include="ref/netcore50;lib/netcore50" />
|
||||
|
||||
@@ -3,7 +3,10 @@
|
||||
<Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.props))\dir.props" />
|
||||
<PropertyGroup>
|
||||
<ProjectGuid>{C4D6F1F4-DC7E-4756-9A88-171A8B1F1E26}</ProjectGuid>
|
||||
<IsPartialFacadeAssembly Condition="'$(TargetGroup)' == 'netfx'">true</IsPartialFacadeAssembly>
|
||||
<!-- Must match version supported by frameworks which support 4.2.* inbox.
|
||||
Can be removed when API is added and this assembly is versioned to 4.3.* -->
|
||||
<AssemblyVersion Condition="'$(TargetsNetFx)' != 'true'">4.2.0.0</AssemblyVersion>
|
||||
<IsPartialFacadeAssembly Condition="'$(TargetsNetFx)' == 'true'">true</IsPartialFacadeAssembly>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'netfx-Debug|AnyCPU'" />
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'netfx-Release|AnyCPU'" />
|
||||
|
||||
@@ -14,11 +14,6 @@ namespace System.ComponentModel.DataAnnotations
|
||||
[Obsolete("This attribute is no longer in use and will be ignored if applied.")]
|
||||
public sealed class AssociationAttribute : Attribute
|
||||
{
|
||||
private string _name;
|
||||
private string _thisKey;
|
||||
private string _otherKey;
|
||||
private bool _isForeignKey;
|
||||
|
||||
/// <summary>
|
||||
/// Full form of constructor
|
||||
/// </summary>
|
||||
@@ -30,78 +25,50 @@ namespace System.ComponentModel.DataAnnotations
|
||||
/// on the other side of the association</param>
|
||||
public AssociationAttribute(string name, string thisKey, string otherKey)
|
||||
{
|
||||
_name = name;
|
||||
_thisKey = thisKey;
|
||||
_otherKey = otherKey;
|
||||
Name = name;
|
||||
ThisKey = thisKey;
|
||||
OtherKey = otherKey;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the name of the association. For bi-directional associations, the name must
|
||||
/// be the same on both sides of the association
|
||||
/// </summary>
|
||||
public string Name
|
||||
{
|
||||
get { return _name; }
|
||||
}
|
||||
public string Name { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets a comma separated list of the property names of the key values
|
||||
/// on this side of the association
|
||||
/// </summary>
|
||||
public string ThisKey
|
||||
{
|
||||
get { return _thisKey; }
|
||||
}
|
||||
public string ThisKey { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets a comma separated list of the property names of the key values
|
||||
/// on the other side of the association
|
||||
/// </summary>
|
||||
public string OtherKey
|
||||
{
|
||||
get { return _otherKey; }
|
||||
}
|
||||
public string OtherKey { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets a value indicating whether this association member represents
|
||||
/// the foreign key side of an association
|
||||
/// </summary>
|
||||
public bool IsForeignKey
|
||||
{
|
||||
get { return _isForeignKey; }
|
||||
set { _isForeignKey = value; }
|
||||
}
|
||||
public bool IsForeignKey { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the collection of individual key members specified in the ThisKey string.
|
||||
/// </summary>
|
||||
public IEnumerable<string> ThisKeyMembers
|
||||
{
|
||||
get
|
||||
{
|
||||
return GetKeyMembers(ThisKey);
|
||||
}
|
||||
}
|
||||
public IEnumerable<string> ThisKeyMembers => GetKeyMembers(ThisKey);
|
||||
|
||||
/// <summary>
|
||||
/// Gets the collection of individual key members specified in the OtherKey string.
|
||||
/// </summary>
|
||||
public IEnumerable<string> OtherKeyMembers
|
||||
{
|
||||
get
|
||||
{
|
||||
return GetKeyMembers(OtherKey);
|
||||
}
|
||||
}
|
||||
public IEnumerable<string> OtherKeyMembers => GetKeyMembers(OtherKey);
|
||||
|
||||
/// <summary>
|
||||
/// Parses the comma delimited key specified
|
||||
/// </summary>
|
||||
/// <param name="key">The key to parse</param>
|
||||
/// <returns>Array of individual key members</returns>
|
||||
private static string[] GetKeyMembers(string key)
|
||||
{
|
||||
return key.Replace(" ", string.Empty).Split(',');
|
||||
}
|
||||
private static string[] GetKeyMembers(string key) => key.Replace(" ", string.Empty).Split(',');
|
||||
}
|
||||
}
|
||||
|
||||
@@ -21,17 +21,15 @@ namespace System.ComponentModel.DataAnnotations
|
||||
OtherProperty = otherProperty;
|
||||
}
|
||||
|
||||
public string OtherProperty { get; private set; }
|
||||
public string OtherProperty { get; }
|
||||
|
||||
public string OtherPropertyDisplayName { get; internal set; }
|
||||
|
||||
public override bool RequiresValidationContext => true;
|
||||
|
||||
public override string FormatErrorMessage(string name)
|
||||
{
|
||||
return string.Format(CultureInfo.CurrentCulture, ErrorMessageString, name,
|
||||
OtherPropertyDisplayName ?? OtherProperty);
|
||||
}
|
||||
public override string FormatErrorMessage(string name) =>
|
||||
string.Format(
|
||||
CultureInfo.CurrentCulture, ErrorMessageString, name, OtherPropertyDisplayName ?? OtherProperty);
|
||||
|
||||
protected override ValidationResult IsValid(object value, ValidationContext validationContext)
|
||||
{
|
||||
@@ -53,14 +51,16 @@ namespace System.ComponentModel.DataAnnotations
|
||||
{
|
||||
if (OtherPropertyDisplayName == null)
|
||||
{
|
||||
OtherPropertyDisplayName = GetDisplayNameForProperty(validationContext.ObjectType, otherPropertyInfo);
|
||||
OtherPropertyDisplayName = GetDisplayNameForProperty(otherPropertyInfo);
|
||||
}
|
||||
|
||||
return new ValidationResult(FormatErrorMessage(validationContext.DisplayName));
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
private string GetDisplayNameForProperty(Type containerType, PropertyInfo property)
|
||||
private string GetDisplayNameForProperty(PropertyInfo property)
|
||||
{
|
||||
var attributes = CustomAttributeExtensions.GetCustomAttributes(property, true);
|
||||
var display = attributes.OfType<DisplayAttribute>().FirstOrDefault();
|
||||
@@ -71,10 +71,5 @@ namespace System.ComponentModel.DataAnnotations
|
||||
|
||||
return OtherProperty;
|
||||
}
|
||||
|
||||
private static bool IsPublic(PropertyInfo p)
|
||||
{
|
||||
return (p.GetMethod != null && p.GetMethod.IsPublic) || (p.SetMethod != null && p.SetMethod.IsPublic);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -60,8 +60,6 @@ namespace System.ComponentModel.DataAnnotations
|
||||
#region Member Fields
|
||||
|
||||
private readonly Lazy<string> _malformedErrorMessage;
|
||||
private readonly string _method;
|
||||
private readonly Type _validatorType;
|
||||
private bool _isSingleArgumentMethod;
|
||||
private string _lastMessage;
|
||||
private MethodInfo _methodInfo;
|
||||
@@ -76,7 +74,7 @@ namespace System.ComponentModel.DataAnnotations
|
||||
/// specified type.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// An invalid <paramref name="validatorType" /> or <paramref name="Method" /> will be cause
|
||||
/// An invalid <paramref name="validatorType" /> or <paramref name="method" /> will be cause
|
||||
/// <see cref="IsValid(object, ValidationContext)" />> to return a <see cref="ValidationResult" />
|
||||
/// and <see cref="ValidationAttribute.FormatErrorMessage" /> to return a summary error message.
|
||||
/// </remarks>
|
||||
@@ -88,8 +86,8 @@ namespace System.ComponentModel.DataAnnotations
|
||||
public CustomValidationAttribute(Type validatorType, string method)
|
||||
: base(() => SR.CustomValidationAttribute_ValidationError)
|
||||
{
|
||||
_validatorType = validatorType;
|
||||
_method = method;
|
||||
ValidatorType = validatorType;
|
||||
Method = method;
|
||||
_malformedErrorMessage = new Lazy<string>(CheckAttributeWellFormed);
|
||||
}
|
||||
|
||||
@@ -100,18 +98,12 @@ namespace System.ComponentModel.DataAnnotations
|
||||
/// <summary>
|
||||
/// Gets the type that contains the validation method identified by <see cref="Method" />.
|
||||
/// </summary>
|
||||
public Type ValidatorType
|
||||
{
|
||||
get { return _validatorType; }
|
||||
}
|
||||
public Type ValidatorType { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the name of the method in <see cref="ValidatorType" /> to invoke to perform validation.
|
||||
/// </summary>
|
||||
public string Method
|
||||
{
|
||||
get { return _method; }
|
||||
}
|
||||
public string Method { get; }
|
||||
|
||||
public override bool RequiresValidationContext
|
||||
{
|
||||
@@ -154,8 +146,8 @@ namespace System.ComponentModel.DataAnnotations
|
||||
SR.CustomValidationAttribute_Type_Conversion_Failed,
|
||||
(value != null ? value.GetType().ToString() : "null"),
|
||||
_firstParameterType,
|
||||
_validatorType,
|
||||
_method));
|
||||
ValidatorType,
|
||||
Method));
|
||||
}
|
||||
|
||||
// Invoke the method. Catch TargetInvocationException merely to unwrap it.
|
||||
@@ -212,10 +204,7 @@ namespace System.ComponentModel.DataAnnotations
|
||||
/// Checks whether the current attribute instance itself is valid for use.
|
||||
/// </summary>
|
||||
/// <returns>The error message why it is not well-formed, null if it is well-formed.</returns>
|
||||
private string CheckAttributeWellFormed()
|
||||
{
|
||||
return ValidateValidatorTypeParameter() ?? ValidateMethodParameter();
|
||||
}
|
||||
private string CheckAttributeWellFormed() => ValidateValidatorTypeParameter() ?? ValidateMethodParameter();
|
||||
|
||||
/// <summary>
|
||||
/// Internal helper to determine whether <see cref="ValidatorType" /> is legal for use.
|
||||
@@ -223,15 +212,15 @@ namespace System.ComponentModel.DataAnnotations
|
||||
/// <returns><c>null</c> or the appropriate error message.</returns>
|
||||
private string ValidateValidatorTypeParameter()
|
||||
{
|
||||
if (_validatorType == null)
|
||||
if (ValidatorType == null)
|
||||
{
|
||||
return SR.CustomValidationAttribute_ValidatorType_Required;
|
||||
}
|
||||
|
||||
if (!_validatorType.IsVisible)
|
||||
if (!ValidatorType.IsVisible)
|
||||
{
|
||||
return string.Format(CultureInfo.CurrentCulture,
|
||||
SR.CustomValidationAttribute_Type_Must_Be_Public, _validatorType.Name);
|
||||
SR.CustomValidationAttribute_Type_Must_Be_Public, ValidatorType.Name);
|
||||
}
|
||||
|
||||
return null;
|
||||
@@ -243,27 +232,27 @@ namespace System.ComponentModel.DataAnnotations
|
||||
/// <returns><c>null</c> or the appropriate error message.</returns>
|
||||
private string ValidateMethodParameter()
|
||||
{
|
||||
if (string.IsNullOrEmpty(_method))
|
||||
if (string.IsNullOrEmpty(Method))
|
||||
{
|
||||
return SR.CustomValidationAttribute_Method_Required;
|
||||
}
|
||||
|
||||
// Named method must be public and static
|
||||
var methodInfo = _validatorType.GetRuntimeMethods()
|
||||
.SingleOrDefault(m => string.Equals(m.Name, _method, StringComparison.Ordinal)
|
||||
var methodInfo = ValidatorType.GetRuntimeMethods()
|
||||
.SingleOrDefault(m => string.Equals(m.Name, Method, StringComparison.Ordinal)
|
||||
&& m.IsPublic && m.IsStatic);
|
||||
if (methodInfo == null)
|
||||
{
|
||||
return string.Format(CultureInfo.CurrentCulture,
|
||||
SR.CustomValidationAttribute_Method_Not_Found, _method, _validatorType.Name);
|
||||
SR.CustomValidationAttribute_Method_Not_Found, Method, ValidatorType.Name);
|
||||
}
|
||||
|
||||
// Method must return a ValidationResult
|
||||
if (methodInfo.ReturnType != typeof(ValidationResult))
|
||||
{
|
||||
return string.Format(CultureInfo.CurrentCulture,
|
||||
SR.CustomValidationAttribute_Method_Must_Return_ValidationResult, _method,
|
||||
_validatorType.Name);
|
||||
SR.CustomValidationAttribute_Method_Must_Return_ValidationResult, Method,
|
||||
ValidatorType.Name);
|
||||
}
|
||||
|
||||
ParameterInfo[] parameterInfos = methodInfo.GetParameters();
|
||||
@@ -272,7 +261,7 @@ namespace System.ComponentModel.DataAnnotations
|
||||
if (parameterInfos.Length == 0 || parameterInfos[0].ParameterType.IsByRef)
|
||||
{
|
||||
return string.Format(CultureInfo.CurrentCulture,
|
||||
SR.CustomValidationAttribute_Method_Signature, _method, _validatorType.Name);
|
||||
SR.CustomValidationAttribute_Method_Signature, Method, ValidatorType.Name);
|
||||
}
|
||||
|
||||
// We accept 2 forms:
|
||||
@@ -285,8 +274,8 @@ namespace System.ComponentModel.DataAnnotations
|
||||
if ((parameterInfos.Length != 2) || (parameterInfos[1].ParameterType != typeof(ValidationContext)))
|
||||
{
|
||||
return string.Format(CultureInfo.CurrentCulture,
|
||||
SR.CustomValidationAttribute_Method_Signature, _method,
|
||||
_validatorType.Name);
|
||||
SR.CustomValidationAttribute_Method_Signature, Method,
|
||||
ValidatorType.Name);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -62,13 +62,13 @@ namespace System.ComponentModel.DataAnnotations
|
||||
/// <summary>
|
||||
/// Gets the DataType. If it equals DataType.Custom, <see cref="CustomDataType" /> should also be retrieved.
|
||||
/// </summary>
|
||||
public DataType DataType { get; private set; }
|
||||
public DataType DataType { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the string representing a custom data type. Returns a non-null value only if <see cref="DataType" /> is
|
||||
/// DataType.Custom.
|
||||
/// </summary>
|
||||
public string CustomDataType { get; private set; }
|
||||
public string CustomDataType { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the default display format that gets used along with this DataType.
|
||||
|
||||
@@ -57,14 +57,8 @@ namespace System.ComponentModel.DataAnnotations
|
||||
/// </value>
|
||||
public string ShortName
|
||||
{
|
||||
get { return _shortName.Value; }
|
||||
set
|
||||
{
|
||||
if (_shortName.Value != value)
|
||||
{
|
||||
_shortName.Value = value;
|
||||
}
|
||||
}
|
||||
get => _shortName.Value;
|
||||
set => _shortName.Value = value;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -88,14 +82,8 @@ namespace System.ComponentModel.DataAnnotations
|
||||
/// </value>
|
||||
public string Name
|
||||
{
|
||||
get { return _name.Value; }
|
||||
set
|
||||
{
|
||||
if (_name.Value != value)
|
||||
{
|
||||
_name.Value = value;
|
||||
}
|
||||
}
|
||||
get => _name.Value;
|
||||
set => _name.Value = value;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -119,14 +107,8 @@ namespace System.ComponentModel.DataAnnotations
|
||||
/// </value>
|
||||
public string Description
|
||||
{
|
||||
get { return _description.Value; }
|
||||
set
|
||||
{
|
||||
if (_description.Value != value)
|
||||
{
|
||||
_description.Value = value;
|
||||
}
|
||||
}
|
||||
get => _description.Value;
|
||||
set => _description.Value = value;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -150,14 +132,8 @@ namespace System.ComponentModel.DataAnnotations
|
||||
/// </value>
|
||||
public string Prompt
|
||||
{
|
||||
get { return _prompt.Value; }
|
||||
set
|
||||
{
|
||||
if (_prompt.Value != value)
|
||||
{
|
||||
_prompt.Value = value;
|
||||
}
|
||||
}
|
||||
get => _prompt.Value;
|
||||
set => _prompt.Value = value;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -181,14 +157,8 @@ namespace System.ComponentModel.DataAnnotations
|
||||
/// </value>
|
||||
public string GroupName
|
||||
{
|
||||
get { return _groupName.Value; }
|
||||
set
|
||||
{
|
||||
if (_groupName.Value != value)
|
||||
{
|
||||
_groupName.Value = value;
|
||||
}
|
||||
}
|
||||
get => _groupName.Value;
|
||||
set => _groupName.Value = value;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -200,7 +170,7 @@ namespace System.ComponentModel.DataAnnotations
|
||||
/// </summary>
|
||||
public Type ResourceType
|
||||
{
|
||||
get { return _resourceType; }
|
||||
get => _resourceType;
|
||||
set
|
||||
{
|
||||
if (_resourceType != value)
|
||||
@@ -240,9 +210,9 @@ namespace System.ComponentModel.DataAnnotations
|
||||
"GetAutoGenerateField"));
|
||||
}
|
||||
|
||||
return _autoGenerateField.Value;
|
||||
return _autoGenerateField.GetValueOrDefault();
|
||||
}
|
||||
set { _autoGenerateField = value; }
|
||||
set => _autoGenerateField = value;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -270,9 +240,9 @@ namespace System.ComponentModel.DataAnnotations
|
||||
"GetAutoGenerateFilter"));
|
||||
}
|
||||
|
||||
return _autoGenerateFilter.Value;
|
||||
return _autoGenerateFilter.GetValueOrDefault();
|
||||
}
|
||||
set { _autoGenerateFilter = value; }
|
||||
set => _autoGenerateFilter = value;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -297,9 +267,9 @@ namespace System.ComponentModel.DataAnnotations
|
||||
SR.DisplayAttribute_PropertyNotSet, "Order", "GetOrder"));
|
||||
}
|
||||
|
||||
return _order.Value;
|
||||
return _order.GetValueOrDefault();
|
||||
}
|
||||
set { _order = value; }
|
||||
set => _order = value;
|
||||
}
|
||||
|
||||
#endregion
|
||||
@@ -330,10 +300,7 @@ namespace System.ComponentModel.DataAnnotations
|
||||
/// but a public static property with a name matching the <see cref="ShortName" /> value couldn't be found
|
||||
/// on the <see cref="ResourceType" />.
|
||||
/// </exception>
|
||||
public string GetShortName()
|
||||
{
|
||||
return _shortName.GetLocalizableValue() ?? GetName();
|
||||
}
|
||||
public string GetShortName() => _shortName.GetLocalizableValue() ?? GetName();
|
||||
|
||||
/// <summary>
|
||||
/// Gets the UI display string for Name.
|
||||
@@ -360,10 +327,7 @@ namespace System.ComponentModel.DataAnnotations
|
||||
/// but a public static property with a name matching the <see cref="Name" /> value couldn't be found
|
||||
/// on the <see cref="ResourceType" />.
|
||||
/// </exception>
|
||||
public string GetName()
|
||||
{
|
||||
return _name.GetLocalizableValue();
|
||||
}
|
||||
public string GetName() => _name.GetLocalizableValue();
|
||||
|
||||
/// <summary>
|
||||
/// Gets the UI display string for Description.
|
||||
@@ -386,10 +350,7 @@ namespace System.ComponentModel.DataAnnotations
|
||||
/// but a public static property with a name matching the <see cref="Description" /> value couldn't be found
|
||||
/// on the <see cref="ResourceType" />.
|
||||
/// </exception>
|
||||
public string GetDescription()
|
||||
{
|
||||
return _description.GetLocalizableValue();
|
||||
}
|
||||
public string GetDescription() => _description.GetLocalizableValue();
|
||||
|
||||
/// <summary>
|
||||
/// Gets the UI display string for Prompt.
|
||||
@@ -412,10 +373,7 @@ namespace System.ComponentModel.DataAnnotations
|
||||
/// but a public static property with a name matching the <see cref="Prompt" /> value couldn't be found
|
||||
/// on the <see cref="ResourceType" />.
|
||||
/// </exception>
|
||||
public string GetPrompt()
|
||||
{
|
||||
return _prompt.GetLocalizableValue();
|
||||
}
|
||||
public string GetPrompt() => _prompt.GetLocalizableValue();
|
||||
|
||||
/// <summary>
|
||||
/// Gets the UI display string for GroupName.
|
||||
@@ -438,10 +396,7 @@ namespace System.ComponentModel.DataAnnotations
|
||||
/// but a public static property with a name matching the <see cref="GroupName" /> value couldn't be found
|
||||
/// on the <see cref="ResourceType" />.
|
||||
/// </exception>
|
||||
public string GetGroupName()
|
||||
{
|
||||
return _groupName.GetLocalizableValue();
|
||||
}
|
||||
public string GetGroupName() => _groupName.GetLocalizableValue();
|
||||
|
||||
/// <summary>
|
||||
/// Gets the value of <see cref="AutoGenerateField" /> if it has been set, or <c>null</c>.
|
||||
@@ -452,10 +407,7 @@ namespace System.ComponentModel.DataAnnotations
|
||||
/// When <see cref="AutoGenerateField" /> has not been set returns <c>null</c>.
|
||||
/// </para>
|
||||
/// </returns>
|
||||
public bool? GetAutoGenerateField()
|
||||
{
|
||||
return _autoGenerateField;
|
||||
}
|
||||
public bool? GetAutoGenerateField() => _autoGenerateField;
|
||||
|
||||
/// <summary>
|
||||
/// Gets the value of <see cref="AutoGenerateFilter" /> if it has been set, or <c>null</c>.
|
||||
@@ -466,10 +418,7 @@ namespace System.ComponentModel.DataAnnotations
|
||||
/// When <see cref="AutoGenerateFilter" /> has not been set returns <c>null</c>.
|
||||
/// </para>
|
||||
/// </returns>
|
||||
public bool? GetAutoGenerateFilter()
|
||||
{
|
||||
return _autoGenerateFilter;
|
||||
}
|
||||
public bool? GetAutoGenerateFilter() => _autoGenerateFilter;
|
||||
|
||||
/// <summary>
|
||||
/// Gets the value of <see cref="Order" /> if it has been set, or <c>null</c>.
|
||||
@@ -485,10 +434,8 @@ namespace System.ComponentModel.DataAnnotations
|
||||
/// of 10000. This value allows for explicitly-ordered fields to be displayed before
|
||||
/// and after the fields that don't specify an order.
|
||||
/// </remarks>
|
||||
public int? GetOrder()
|
||||
{
|
||||
return _order;
|
||||
}
|
||||
public int? GetOrder() => _order;
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
|
||||
@@ -28,10 +28,10 @@ namespace System.ComponentModel.DataAnnotations
|
||||
SortDescending = sortDescending;
|
||||
}
|
||||
|
||||
public string DisplayColumn { get; private set; }
|
||||
public string DisplayColumn { get; }
|
||||
|
||||
public string SortColumn { get; private set; }
|
||||
public string SortColumn { get; }
|
||||
|
||||
public bool SortDescending { get; private set; }
|
||||
public bool SortDescending { get; }
|
||||
}
|
||||
}
|
||||
|
||||
@@ -44,13 +44,13 @@ namespace System.ComponentModel.DataAnnotations
|
||||
/// </para>
|
||||
/// </remarks>
|
||||
/// <value>
|
||||
/// The null dispay text is generally used as placeholder when the value is not specified.
|
||||
/// The null display text is generally used as placeholder when the value is not specified.
|
||||
/// A <c>null</c> or empty string is legal, and consumers must allow for that.
|
||||
/// </value>
|
||||
public string NullDisplayText
|
||||
{
|
||||
get { return _nullDisplayText.Value; }
|
||||
set { _nullDisplayText.Value = value; }
|
||||
get => _nullDisplayText.Value;
|
||||
set => _nullDisplayText.Value = value;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -75,8 +75,8 @@ namespace System.ComponentModel.DataAnnotations
|
||||
/// </summary>
|
||||
public Type NullDisplayTextResourceType
|
||||
{
|
||||
get { return _nullDisplayText.ResourceType; }
|
||||
set { _nullDisplayText.ResourceType = value; }
|
||||
get => _nullDisplayText.ResourceType;
|
||||
set => _nullDisplayText.ResourceType = value;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -103,9 +103,6 @@ namespace System.ComponentModel.DataAnnotations
|
||||
/// but a public static property with a name matching the <see cref="NullDisplayText" /> value couldn't be found
|
||||
/// on the <see cref="NullDisplayTextResourceType" />.
|
||||
/// </exception>
|
||||
public string GetNullDisplayText()
|
||||
{
|
||||
return _nullDisplayText.GetLocalizableValue();
|
||||
}
|
||||
public string GetNullDisplayText() => _nullDisplayText.GetLocalizableValue();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -42,7 +42,7 @@ namespace System.ComponentModel.DataAnnotations
|
||||
/// When <c>false</c>, the field/property is not editable.
|
||||
/// </para>
|
||||
/// </value>
|
||||
public bool AllowEdit { get; private set; }
|
||||
public bool AllowEdit { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Indicates whether or not the field/property allows an initial value
|
||||
|
||||
@@ -5,7 +5,6 @@
|
||||
using System.Diagnostics;
|
||||
using System.Globalization;
|
||||
using System.Linq;
|
||||
using System.Reflection;
|
||||
|
||||
namespace System.ComponentModel.DataAnnotations
|
||||
{
|
||||
@@ -20,7 +19,7 @@ namespace System.ComponentModel.DataAnnotations
|
||||
EnumType = enumType;
|
||||
}
|
||||
|
||||
public Type EnumType { get; private set; }
|
||||
public Type EnumType { get; }
|
||||
|
||||
public override bool IsValid(object value)
|
||||
{
|
||||
@@ -107,16 +106,10 @@ namespace System.ComponentModel.DataAnnotations
|
||||
return Enum.IsDefined(EnumType, convertedValue);
|
||||
}
|
||||
|
||||
private static bool IsEnumTypeInFlagsMode(Type enumType)
|
||||
{
|
||||
return enumType.GetCustomAttributes(typeof(FlagsAttribute), false).Any();
|
||||
}
|
||||
private static bool IsEnumTypeInFlagsMode(Type enumType) =>
|
||||
enumType.GetCustomAttributes(typeof(FlagsAttribute), false).Any();
|
||||
|
||||
|
||||
private static string GetUnderlyingTypeValueString(Type enumType, object enumValue)
|
||||
{
|
||||
return
|
||||
Convert.ChangeType(enumValue, Enum.GetUnderlyingType(enumType), CultureInfo.InvariantCulture).ToString();
|
||||
}
|
||||
private static string GetUnderlyingTypeValueString(Type enumType, object enumValue) =>
|
||||
Convert.ChangeType(enumValue, Enum.GetUnderlyingType(enumType), CultureInfo.InvariantCulture).ToString();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -25,34 +25,23 @@ namespace System.ComponentModel.DataAnnotations
|
||||
|
||||
public string Extensions
|
||||
{
|
||||
get
|
||||
{
|
||||
// Default file extensions match those from jquery validate.
|
||||
return string.IsNullOrWhiteSpace(_extensions) ? "png,jpg,jpeg,gif" : _extensions;
|
||||
}
|
||||
set { _extensions = value; }
|
||||
// Default file extensions match those from jquery validate.
|
||||
get => string.IsNullOrWhiteSpace(_extensions) ? "png,jpg,jpeg,gif" : _extensions;
|
||||
set => _extensions = value;
|
||||
}
|
||||
|
||||
private string ExtensionsFormatted
|
||||
{
|
||||
get { return ExtensionsParsed.Aggregate((left, right) => left + ", " + right); }
|
||||
}
|
||||
private string ExtensionsFormatted => ExtensionsParsed.Aggregate((left, right) => left + ", " + right);
|
||||
|
||||
|
||||
private string ExtensionsNormalized
|
||||
{
|
||||
get { return Extensions.Replace(" ", string.Empty).Replace(".", string.Empty).ToLowerInvariant(); }
|
||||
}
|
||||
private string ExtensionsNormalized =>
|
||||
Extensions.Replace(" ", string.Empty).Replace(".", string.Empty).ToLowerInvariant();
|
||||
|
||||
private IEnumerable<string> ExtensionsParsed
|
||||
{
|
||||
get { return ExtensionsNormalized.Split(',').Select(e => "." + e); }
|
||||
}
|
||||
|
||||
public override string FormatErrorMessage(string name)
|
||||
{
|
||||
return string.Format(CultureInfo.CurrentCulture, ErrorMessageString, name, ExtensionsFormatted);
|
||||
}
|
||||
public override string FormatErrorMessage(string name) =>
|
||||
string.Format(CultureInfo.CurrentCulture, ErrorMessageString, name, ExtensionsFormatted);
|
||||
|
||||
public override bool IsValid(object value)
|
||||
{
|
||||
|
||||
@@ -13,44 +13,26 @@ namespace System.ComponentModel.DataAnnotations
|
||||
[Obsolete("This attribute is no longer in use and will be ignored if applied.")]
|
||||
public sealed class FilterUIHintAttribute : Attribute
|
||||
{
|
||||
private UIHintAttribute.UIHintImplementation _implementation;
|
||||
private readonly UIHintAttribute.UIHintImplementation _implementation;
|
||||
|
||||
/// <summary>
|
||||
/// Gets the name of the control that is most appropriate for this associated
|
||||
/// property or field
|
||||
/// </summary>
|
||||
public string FilterUIHint
|
||||
{
|
||||
get
|
||||
{
|
||||
return this._implementation.UIHint;
|
||||
}
|
||||
}
|
||||
public string FilterUIHint => _implementation.UIHint;
|
||||
|
||||
/// <summary>
|
||||
/// Gets the name of the presentation layer that supports the control type
|
||||
/// in <see cref="FilterUIHint"/>
|
||||
/// </summary>
|
||||
public string PresentationLayer
|
||||
{
|
||||
get
|
||||
{
|
||||
return this._implementation.PresentationLayer;
|
||||
}
|
||||
}
|
||||
public string PresentationLayer => _implementation.PresentationLayer;
|
||||
|
||||
/// <summary>
|
||||
/// Gets the name-value pairs used as parameters to the control's constructor
|
||||
/// </summary>
|
||||
/// <exception cref="InvalidOperationException"> is thrown if the current attribute
|
||||
/// is ill-formed.</exception>
|
||||
public IDictionary<string, object> ControlParameters
|
||||
{
|
||||
get
|
||||
{
|
||||
return this._implementation.ControlParameters;
|
||||
}
|
||||
}
|
||||
public IDictionary<string, object> ControlParameters => _implementation.ControlParameters;
|
||||
|
||||
/// <summary>
|
||||
/// Constructor that accepts the name of the control, without specifying
|
||||
@@ -84,7 +66,7 @@ namespace System.ComponentModel.DataAnnotations
|
||||
public FilterUIHintAttribute(string filterUIHint, string presentationLayer,
|
||||
params object[] controlParameters)
|
||||
{
|
||||
this._implementation = new UIHintAttribute.UIHintImplementation(
|
||||
_implementation = new UIHintAttribute.UIHintImplementation(
|
||||
filterUIHint, presentationLayer, controlParameters);
|
||||
}
|
||||
|
||||
@@ -92,10 +74,7 @@ namespace System.ComponentModel.DataAnnotations
|
||||
/// Returns the hash code for this FilterUIHintAttribute.
|
||||
/// </summary>
|
||||
/// <returns>A 32-bit signed integer hash code.</returns>
|
||||
public override int GetHashCode()
|
||||
{
|
||||
return this._implementation.GetHashCode();
|
||||
}
|
||||
public override int GetHashCode() => _implementation.GetHashCode();
|
||||
|
||||
/// <summary>
|
||||
/// Determines whether this instance of FilterUIHintAttribute and a specified object,
|
||||
@@ -112,7 +91,7 @@ namespace System.ComponentModel.DataAnnotations
|
||||
return false;
|
||||
}
|
||||
|
||||
return this._implementation.Equals(otherAttribute._implementation);
|
||||
return _implementation.Equals(otherAttribute._implementation);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -49,7 +49,7 @@ namespace System.ComponentModel.DataAnnotations
|
||||
/// </summary>
|
||||
public string Value
|
||||
{
|
||||
get { return _propertyValue; }
|
||||
get => _propertyValue;
|
||||
set
|
||||
{
|
||||
if (_propertyValue != value)
|
||||
@@ -65,7 +65,7 @@ namespace System.ComponentModel.DataAnnotations
|
||||
/// </summary>
|
||||
public Type ResourceType
|
||||
{
|
||||
get { return _resourceType; }
|
||||
get => _resourceType;
|
||||
set
|
||||
{
|
||||
if (_resourceType != value)
|
||||
|
||||
@@ -3,7 +3,9 @@
|
||||
// See the LICENSE file in the project root for more information.
|
||||
|
||||
using System.Collections;
|
||||
using System.Diagnostics;
|
||||
using System.Globalization;
|
||||
using System.Reflection;
|
||||
|
||||
namespace System.ComponentModel.DataAnnotations
|
||||
{
|
||||
@@ -42,12 +44,9 @@ namespace System.ComponentModel.DataAnnotations
|
||||
/// <summary>
|
||||
/// Gets the maximum allowable length of the collection/string data.
|
||||
/// </summary>
|
||||
public int Length { get; private set; }
|
||||
public int Length { get; }
|
||||
|
||||
private static string DefaultErrorMessageString
|
||||
{
|
||||
get { return SR.MaxLengthAttribute_ValidationError; }
|
||||
}
|
||||
private static string DefaultErrorMessageString => SR.MaxLengthAttribute_ValidationError;
|
||||
|
||||
/// <summary>
|
||||
/// Determines whether a specified object is valid. (Overrides <see cref="ValidationAttribute.IsValid(object)" />)
|
||||
@@ -76,16 +75,13 @@ namespace System.ComponentModel.DataAnnotations
|
||||
{
|
||||
length = str.Length;
|
||||
}
|
||||
else if (CountPropertyHelper.TryGetCount(value, out var count))
|
||||
{
|
||||
length = count;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (value is ICollection collection)
|
||||
{
|
||||
length = collection.Count;
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new InvalidCastException(SR.Format(SR.LengthAttribute_InvalidValueType, value.GetType()));
|
||||
}
|
||||
throw new InvalidCastException(SR.Format(SR.LengthAttribute_InvalidValueType, value.GetType()));
|
||||
}
|
||||
|
||||
return MaxAllowableLength == Length || length <= Length;
|
||||
@@ -96,11 +92,9 @@ namespace System.ComponentModel.DataAnnotations
|
||||
/// </summary>
|
||||
/// <param name="name">The name to include in the formatted string.</param>
|
||||
/// <returns>A localized string to describe the maximum acceptable length.</returns>
|
||||
public override string FormatErrorMessage(string name)
|
||||
{
|
||||
public override string FormatErrorMessage(string name) =>
|
||||
// An error occurred, so we know the value is greater than the maximum if it was specified
|
||||
return string.Format(CultureInfo.CurrentCulture, ErrorMessageString, name, Length);
|
||||
}
|
||||
string.Format(CultureInfo.CurrentCulture, ErrorMessageString, name, Length);
|
||||
|
||||
/// <summary>
|
||||
/// Checks that Length has a legal value.
|
||||
@@ -115,4 +109,28 @@ namespace System.ComponentModel.DataAnnotations
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
internal static class CountPropertyHelper
|
||||
{
|
||||
public static bool TryGetCount(object value, out int count)
|
||||
{
|
||||
Debug.Assert(value != null);
|
||||
|
||||
if (value is ICollection collection)
|
||||
{
|
||||
count = collection.Count;
|
||||
return true;
|
||||
}
|
||||
|
||||
PropertyInfo property = value.GetType().GetRuntimeProperty("Count");
|
||||
if (property != null && property.CanRead && property.PropertyType == typeof(int))
|
||||
{
|
||||
count = (int)property.GetValue(value);
|
||||
return true;
|
||||
}
|
||||
|
||||
count = -1;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,7 +2,6 @@
|
||||
// The .NET Foundation licenses this file to you under the MIT license.
|
||||
// See the LICENSE file in the project root for more information.
|
||||
|
||||
using System.Collections;
|
||||
using System.Globalization;
|
||||
|
||||
namespace System.ComponentModel.DataAnnotations
|
||||
@@ -30,7 +29,7 @@ namespace System.ComponentModel.DataAnnotations
|
||||
/// <summary>
|
||||
/// Gets the minimum allowable length of the collection/string data.
|
||||
/// </summary>
|
||||
public int Length { get; private set; }
|
||||
public int Length { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Determines whether a specified object is valid. (Overrides <see cref="ValidationAttribute.IsValid(object)" />)
|
||||
@@ -60,16 +59,13 @@ namespace System.ComponentModel.DataAnnotations
|
||||
{
|
||||
length = str.Length;
|
||||
}
|
||||
else if (CountPropertyHelper.TryGetCount(value, out var count))
|
||||
{
|
||||
length = count;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (value is ICollection collection)
|
||||
{
|
||||
length = collection.Count;
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new InvalidCastException(SR.Format(SR.LengthAttribute_InvalidValueType, value.GetType()));
|
||||
}
|
||||
throw new InvalidCastException(SR.Format(SR.LengthAttribute_InvalidValueType, value.GetType()));
|
||||
}
|
||||
|
||||
return length >= Length;
|
||||
@@ -80,11 +76,9 @@ namespace System.ComponentModel.DataAnnotations
|
||||
/// </summary>
|
||||
/// <param name="name">The name to include in the formatted string.</param>
|
||||
/// <returns>A localized string to describe the minimum acceptable length.</returns>
|
||||
public override string FormatErrorMessage(string name)
|
||||
{
|
||||
public override string FormatErrorMessage(string name) =>
|
||||
// An error occurred, so we know the value is less than the minimum
|
||||
return string.Format(CultureInfo.CurrentCulture, ErrorMessageString, name, Length);
|
||||
}
|
||||
string.Format(CultureInfo.CurrentCulture, ErrorMessageString, name, Length);
|
||||
|
||||
/// <summary>
|
||||
/// Checks that Length has a legal value.
|
||||
|
||||
@@ -3,7 +3,6 @@
|
||||
// See the LICENSE file in the project root for more information.
|
||||
|
||||
using System.Globalization;
|
||||
using System.Reflection;
|
||||
|
||||
namespace System.ComponentModel.DataAnnotations
|
||||
{
|
||||
@@ -69,7 +68,7 @@ namespace System.ComponentModel.DataAnnotations
|
||||
/// Gets the type of the <see cref="Minimum" /> and <see cref="Maximum" /> values (e.g. Int32, Double, or some custom
|
||||
/// type)
|
||||
/// </summary>
|
||||
public Type OperandType { get; private set; }
|
||||
public Type OperandType { get; }
|
||||
|
||||
private Func<object, object> Conversion { get; set; }
|
||||
|
||||
|
||||
@@ -34,7 +34,7 @@ namespace System.ComponentModel.DataAnnotations
|
||||
/// <summary>
|
||||
/// Gets the regular expression pattern to use
|
||||
/// </summary>
|
||||
public string Pattern { get; private set; }
|
||||
public string Pattern { get; }
|
||||
|
||||
private Regex Regex { get; set; }
|
||||
|
||||
|
||||
@@ -12,6 +12,6 @@ namespace System.ComponentModel.DataAnnotations
|
||||
Scaffold = scaffold;
|
||||
}
|
||||
|
||||
public bool Scaffold { get; private set; }
|
||||
public bool Scaffold { get; }
|
||||
}
|
||||
}
|
||||
|
||||
@@ -12,7 +12,6 @@ namespace System.ComponentModel.DataAnnotations.Schema
|
||||
[AttributeUsage(AttributeTargets.Property | AttributeTargets.Field, AllowMultiple = false)]
|
||||
public class ColumnAttribute : Attribute
|
||||
{
|
||||
private readonly string _name;
|
||||
private int _order = -1;
|
||||
private string _typeName;
|
||||
|
||||
@@ -35,23 +34,20 @@ namespace System.ComponentModel.DataAnnotations.Schema
|
||||
SR.ArgumentIsNullOrWhitespace, nameof(name)));
|
||||
}
|
||||
|
||||
_name = name;
|
||||
Name = name;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// The name of the column the property is mapped to.
|
||||
/// </summary>
|
||||
public string Name
|
||||
{
|
||||
get { return _name; }
|
||||
}
|
||||
public string Name { get; }
|
||||
|
||||
/// <summary>
|
||||
/// The zero-based order of the column the property is mapped to.
|
||||
/// </summary>
|
||||
public int Order
|
||||
{
|
||||
get { return _order; }
|
||||
get => _order;
|
||||
set
|
||||
{
|
||||
if (value < 0)
|
||||
@@ -68,7 +64,7 @@ namespace System.ComponentModel.DataAnnotations.Schema
|
||||
/// </summary>
|
||||
public string TypeName
|
||||
{
|
||||
get { return _typeName; }
|
||||
get => _typeName;
|
||||
set
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(value))
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user