You've already forked linux-packaging-mono
Imported Upstream version 5.0.0.42
Former-commit-id: fd56571888259555122d8a0f58c68838229cea2b
This commit is contained in:
parent
1190d13a04
commit
6bdd276d05
46
external/corefx/src/System.ComponentModel.Annotations/System.ComponentModel.Annotations.sln
vendored
Normal file
46
external/corefx/src/System.ComponentModel.Annotations/System.ComponentModel.Annotations.sln
vendored
Normal file
@@ -0,0 +1,46 @@
|
||||
|
||||
Microsoft Visual Studio Solution File, Format Version 12.00
|
||||
# Visual Studio 2013
|
||||
VisualStudioVersion = 12.0.30723.0
|
||||
MinimumVisualStudioVersion = 10.0.40219.1
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "System.ComponentModel.Annotations.Tests", "tests\System.ComponentModel.Annotations.Tests.csproj", "{6E48765E-D6AC-4A79-9C2E-B5EE67EEDECF}"
|
||||
ProjectSection(ProjectDependencies) = postProject
|
||||
{4266D58F-EB60-46C2-BA81-3ABDE759A7D5} = {4266D58F-EB60-46C2-BA81-3ABDE759A7D5}
|
||||
EndProjectSection
|
||||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "System.ComponentModel.Annotations", "src\System.ComponentModel.Annotations.csproj", "{4266D58F-EB60-46C2-BA81-3ABDE759A7D5}"
|
||||
EndProject
|
||||
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = ".nuget", ".nuget", "{3A3E1C22-FF83-4D70-A94A-6C130805E6BF}"
|
||||
ProjectSection(SolutionItems) = preProject
|
||||
..\.nuget\packages.Windows_NT.config = ..\.nuget\packages.Windows_NT.config
|
||||
EndProjectSection
|
||||
EndProject
|
||||
Global
|
||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||
DebugNETCoreAppnet463-Windows_NTnetstandard|AnyCPU = DebugNETCoreAppnet463-Windows_NTnetstandard|AnyCPU
|
||||
ReleaseNETCoreAppnet463-Windows_NTnetstandard|AnyCPU = ReleaseNETCoreAppnet463-Windows_NTnetstandard|AnyCPU
|
||||
DebugNETCoreAppnetstandardnetstandard|AnyCPU = DebugNETCoreAppnetstandardnetstandard|AnyCPU
|
||||
ReleaseNETCoreAppnetstandardnetstandard|AnyCPU = ReleaseNETCoreAppnetstandardnetstandard|AnyCPU
|
||||
EndGlobalSection
|
||||
GlobalSection(ProjectConfigurationPlatforms) = postSolution
|
||||
{6E48765E-D6AC-4A79-9C2E-B5EE67EEDECF}.DebugNETCoreAppnet463-Windows_NTnetstandard|AnyCPU.ActiveCfg = netstandard-Debug|Any CPU
|
||||
{6E48765E-D6AC-4A79-9C2E-B5EE67EEDECF}.DebugNETCoreAppnet463-Windows_NTnetstandard|AnyCPU.Build.0 = netstandard-Debug|Any CPU
|
||||
{6E48765E-D6AC-4A79-9C2E-B5EE67EEDECF}.ReleaseNETCoreAppnet463-Windows_NTnetstandard|AnyCPU.ActiveCfg = netstandard-Release|Any CPU
|
||||
{6E48765E-D6AC-4A79-9C2E-B5EE67EEDECF}.ReleaseNETCoreAppnet463-Windows_NTnetstandard|AnyCPU.Build.0 = netstandard-Release|Any CPU
|
||||
{6E48765E-D6AC-4A79-9C2E-B5EE67EEDECF}.DebugNETCoreAppnetstandardnetstandard|AnyCPU.ActiveCfg = netstandard-Debug|Any CPU
|
||||
{6E48765E-D6AC-4A79-9C2E-B5EE67EEDECF}.DebugNETCoreAppnetstandardnetstandard|AnyCPU.Build.0 = netstandard-Debug|Any CPU
|
||||
{6E48765E-D6AC-4A79-9C2E-B5EE67EEDECF}.ReleaseNETCoreAppnetstandardnetstandard|AnyCPU.ActiveCfg = netstandard-Release|Any CPU
|
||||
{6E48765E-D6AC-4A79-9C2E-B5EE67EEDECF}.ReleaseNETCoreAppnetstandardnetstandard|AnyCPU.Build.0 = netstandard-Release|Any CPU
|
||||
{4266D58F-EB60-46C2-BA81-3ABDE759A7D5}.DebugNETCoreAppnet463-Windows_NTnetstandard|AnyCPU.ActiveCfg = net463-Windows_NT-Debug|Any CPU
|
||||
{4266D58F-EB60-46C2-BA81-3ABDE759A7D5}.DebugNETCoreAppnet463-Windows_NTnetstandard|AnyCPU.Build.0 = net463-Windows_NT-Debug|Any CPU
|
||||
{4266D58F-EB60-46C2-BA81-3ABDE759A7D5}.ReleaseNETCoreAppnet463-Windows_NTnetstandard|AnyCPU.ActiveCfg = net463-Windows_NT-Release|Any CPU
|
||||
{4266D58F-EB60-46C2-BA81-3ABDE759A7D5}.ReleaseNETCoreAppnet463-Windows_NTnetstandard|AnyCPU.Build.0 = net463-Windows_NT-Release|Any CPU
|
||||
{4266D58F-EB60-46C2-BA81-3ABDE759A7D5}.DebugNETCoreAppnetstandardnetstandard|AnyCPU.ActiveCfg = netstandard-Debug|Any CPU
|
||||
{4266D58F-EB60-46C2-BA81-3ABDE759A7D5}.DebugNETCoreAppnetstandardnetstandard|AnyCPU.Build.0 = netstandard-Debug|Any CPU
|
||||
{4266D58F-EB60-46C2-BA81-3ABDE759A7D5}.ReleaseNETCoreAppnetstandardnetstandard|AnyCPU.ActiveCfg = netstandard-Release|Any CPU
|
||||
{4266D58F-EB60-46C2-BA81-3ABDE759A7D5}.ReleaseNETCoreAppnetstandardnetstandard|AnyCPU.Build.0 = netstandard-Release|Any CPU
|
||||
EndGlobalSection
|
||||
GlobalSection(SolutionProperties) = preSolution
|
||||
HideSolutionNode = FALSE
|
||||
EndGlobalSection
|
||||
EndGlobal
|
||||
8
external/corefx/src/System.ComponentModel.Annotations/dir.props
vendored
Normal file
8
external/corefx/src/System.ComponentModel.Annotations/dir.props
vendored
Normal file
@@ -0,0 +1,8 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project ToolsVersion="14.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<Import Project="..\dir.props" />
|
||||
<PropertyGroup>
|
||||
<AssemblyVersion>4.2.0.0</AssemblyVersion>
|
||||
<IsNETCoreApp>true</IsNETCoreApp>
|
||||
</PropertyGroup>
|
||||
</Project>
|
||||
@@ -0,0 +1,8 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project ToolsVersion="14.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.props))\dir.props" />
|
||||
<ItemGroup>
|
||||
<Project Include="System.ComponentModel.Annotations.pkgproj" />
|
||||
</ItemGroup>
|
||||
<Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.traversal.targets))\dir.traversal.targets" />
|
||||
</Project>
|
||||
@@ -0,0 +1,22 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project ToolsVersion="14.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.props))\dir.props" />
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\ref\System.ComponentModel.Annotations.csproj">
|
||||
<SupportedFramework>net463;netcoreapp2.0;$(AllXamarinFrameworks)</SupportedFramework>
|
||||
</ProjectReference>
|
||||
<ProjectReference Include="..\src\System.ComponentModel.Annotations.builds" />
|
||||
<InboxOnTargetFramework Include="MonoAndroid10" />
|
||||
<InboxOnTargetFramework Include="MonoTouch10" />
|
||||
<InboxOnTargetFramework Include="net45">
|
||||
<FrameworkReference>System.ComponentModel.DataAnnotations</FrameworkReference>
|
||||
</InboxOnTargetFramework>
|
||||
<InboxOnTargetFramework Include="win8" />
|
||||
<InboxOnTargetFramework Include="portable-net45+win8" />
|
||||
<InboxOnTargetFramework Include="xamarinios10" />
|
||||
<InboxOnTargetFramework Include="xamarinmac20" />
|
||||
<InboxOnTargetFramework Include="xamarintvos10" />
|
||||
<InboxOnTargetFramework Include="xamarinwatchos10" />
|
||||
</ItemGroup>
|
||||
<Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.targets))\dir.targets" />
|
||||
</Project>
|
||||
8
external/corefx/src/System.ComponentModel.Annotations/ref/Configurations.props
vendored
Normal file
8
external/corefx/src/System.ComponentModel.Annotations/ref/Configurations.props
vendored
Normal file
@@ -0,0 +1,8 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project ToolsVersion="14.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<PropertyGroup>
|
||||
<BuildConfigurations>
|
||||
netstandard;
|
||||
</BuildConfigurations>
|
||||
</PropertyGroup>
|
||||
</Project>
|
||||
381
external/corefx/src/System.ComponentModel.Annotations/ref/System.ComponentModel.Annotations.cs
vendored
Normal file
381
external/corefx/src/System.ComponentModel.Annotations/ref/System.ComponentModel.Annotations.cs
vendored
Normal file
@@ -0,0 +1,381 @@
|
||||
// Licensed to the .NET Foundation under one or more agreements.
|
||||
// The .NET Foundation licenses this file to you under the MIT license.
|
||||
// See the LICENSE file in the project root for more information.
|
||||
// ------------------------------------------------------------------------------
|
||||
// Changes to this file must follow the http://aka.ms/api-review process.
|
||||
// ------------------------------------------------------------------------------
|
||||
|
||||
|
||||
namespace System.ComponentModel.DataAnnotations
|
||||
{
|
||||
[System.AttributeUsageAttribute((System.AttributeTargets)(384), AllowMultiple = false, Inherited = true)]
|
||||
[System.ObsoleteAttribute("This attribute is no longer in use and will be ignored if applied.")]
|
||||
public sealed partial class AssociationAttribute : System.Attribute
|
||||
{
|
||||
public AssociationAttribute(string name, string thisKey, string otherKey) { }
|
||||
public bool IsForeignKey { get { throw null; } set { } }
|
||||
public string Name { get { throw null; } }
|
||||
public string OtherKey { get { throw null; } }
|
||||
public System.Collections.Generic.IEnumerable<string> OtherKeyMembers { get { throw null; } }
|
||||
public string ThisKey { get { throw null; } }
|
||||
public System.Collections.Generic.IEnumerable<string> ThisKeyMembers { get { throw null; } }
|
||||
}
|
||||
[System.AttributeUsageAttribute((System.AttributeTargets)(128), AllowMultiple = false)]
|
||||
public partial class CompareAttribute : System.ComponentModel.DataAnnotations.ValidationAttribute
|
||||
{
|
||||
public CompareAttribute(string otherProperty) { }
|
||||
public string OtherProperty { get { throw null; } }
|
||||
public string OtherPropertyDisplayName { get { throw null; } }
|
||||
public override bool RequiresValidationContext { get { throw null; } }
|
||||
public override string FormatErrorMessage(string name) { throw null; }
|
||||
protected override System.ComponentModel.DataAnnotations.ValidationResult IsValid(object value, System.ComponentModel.DataAnnotations.ValidationContext validationContext) { throw null; }
|
||||
}
|
||||
[System.AttributeUsageAttribute((System.AttributeTargets)(384), AllowMultiple = false, Inherited = true)]
|
||||
public sealed partial class ConcurrencyCheckAttribute : System.Attribute
|
||||
{
|
||||
public ConcurrencyCheckAttribute() { }
|
||||
}
|
||||
[System.AttributeUsageAttribute((System.AttributeTargets)(2432), AllowMultiple = false)]
|
||||
public sealed partial class CreditCardAttribute : System.ComponentModel.DataAnnotations.DataTypeAttribute
|
||||
{
|
||||
public CreditCardAttribute() : base(default(System.ComponentModel.DataAnnotations.DataType)) { }
|
||||
public override bool IsValid(object value) { throw null; }
|
||||
}
|
||||
[System.AttributeUsageAttribute((System.AttributeTargets)(2500), AllowMultiple = true)]
|
||||
public sealed partial class CustomValidationAttribute : System.ComponentModel.DataAnnotations.ValidationAttribute
|
||||
{
|
||||
public CustomValidationAttribute(System.Type validatorType, string method) { }
|
||||
public string Method { get { throw null; } }
|
||||
public System.Type ValidatorType { get { throw null; } }
|
||||
public override string FormatErrorMessage(string name) { throw null; }
|
||||
protected override System.ComponentModel.DataAnnotations.ValidationResult IsValid(object value, System.ComponentModel.DataAnnotations.ValidationContext validationContext) { throw null; }
|
||||
}
|
||||
public enum DataType
|
||||
{
|
||||
CreditCard = 14,
|
||||
Currency = 6,
|
||||
Custom = 0,
|
||||
Date = 2,
|
||||
DateTime = 1,
|
||||
Duration = 4,
|
||||
EmailAddress = 10,
|
||||
Html = 8,
|
||||
ImageUrl = 13,
|
||||
MultilineText = 9,
|
||||
Password = 11,
|
||||
PhoneNumber = 5,
|
||||
PostalCode = 15,
|
||||
Text = 7,
|
||||
Time = 3,
|
||||
Upload = 16,
|
||||
Url = 12,
|
||||
}
|
||||
[System.AttributeUsageAttribute((System.AttributeTargets)(2496), AllowMultiple = false)]
|
||||
public partial class DataTypeAttribute : System.ComponentModel.DataAnnotations.ValidationAttribute
|
||||
{
|
||||
public DataTypeAttribute(System.ComponentModel.DataAnnotations.DataType dataType) { }
|
||||
public DataTypeAttribute(string customDataType) { }
|
||||
public string CustomDataType { get { throw null; } }
|
||||
public System.ComponentModel.DataAnnotations.DataType DataType { get { throw null; } }
|
||||
public System.ComponentModel.DataAnnotations.DisplayFormatAttribute DisplayFormat { get { throw null; } protected set { } }
|
||||
public virtual string GetDataTypeName() { throw null; }
|
||||
public override bool IsValid(object value) { throw null; }
|
||||
}
|
||||
[System.AttributeUsageAttribute((System.AttributeTargets)(2496), AllowMultiple = false)]
|
||||
public sealed partial class DisplayAttribute : System.Attribute
|
||||
{
|
||||
public DisplayAttribute() { }
|
||||
public bool AutoGenerateField { get { throw null; } set { } }
|
||||
public bool AutoGenerateFilter { get { throw null; } set { } }
|
||||
public string Description { get { throw null; } set { } }
|
||||
public string GroupName { get { throw null; } set { } }
|
||||
public string Name { get { throw null; } set { } }
|
||||
public int Order { get { throw null; } set { } }
|
||||
public string Prompt { get { throw null; } set { } }
|
||||
public System.Type ResourceType { get { throw null; } set { } }
|
||||
public string ShortName { get { throw null; } set { } }
|
||||
public System.Nullable<bool> GetAutoGenerateField() { throw null; }
|
||||
public System.Nullable<bool> GetAutoGenerateFilter() { throw null; }
|
||||
public string GetDescription() { throw null; }
|
||||
public string GetGroupName() { throw null; }
|
||||
public string GetName() { throw null; }
|
||||
public System.Nullable<int> GetOrder() { throw null; }
|
||||
public string GetPrompt() { throw null; }
|
||||
public string GetShortName() { throw null; }
|
||||
}
|
||||
[System.AttributeUsageAttribute((System.AttributeTargets)(4), Inherited = true, AllowMultiple = false)]
|
||||
public partial class DisplayColumnAttribute : System.Attribute
|
||||
{
|
||||
public DisplayColumnAttribute(string displayColumn) { }
|
||||
public DisplayColumnAttribute(string displayColumn, string sortColumn) { }
|
||||
public DisplayColumnAttribute(string displayColumn, string sortColumn, bool sortDescending) { }
|
||||
public string DisplayColumn { get { throw null; } }
|
||||
public string SortColumn { get { throw null; } }
|
||||
public bool SortDescending { get { throw null; } }
|
||||
}
|
||||
[System.AttributeUsageAttribute((System.AttributeTargets)(384), AllowMultiple = false)]
|
||||
public partial class DisplayFormatAttribute : System.Attribute
|
||||
{
|
||||
public DisplayFormatAttribute() { }
|
||||
public bool ApplyFormatInEditMode { get { throw null; } set { } }
|
||||
public bool ConvertEmptyStringToNull { get { throw null; } set { } }
|
||||
public string DataFormatString { get { throw null; } set { } }
|
||||
public bool HtmlEncode { get { throw null; } set { } }
|
||||
public string NullDisplayText { get { throw null; } set { } }
|
||||
}
|
||||
[System.AttributeUsageAttribute((System.AttributeTargets)(384), AllowMultiple = false, Inherited = true)]
|
||||
public sealed partial class EditableAttribute : System.Attribute
|
||||
{
|
||||
public EditableAttribute(bool allowEdit) { }
|
||||
public bool AllowEdit { get { throw null; } }
|
||||
public bool AllowInitialValue { get { throw null; } set { } }
|
||||
}
|
||||
[System.AttributeUsageAttribute((System.AttributeTargets)(2432), AllowMultiple = false)]
|
||||
public sealed partial class EmailAddressAttribute : System.ComponentModel.DataAnnotations.DataTypeAttribute
|
||||
{
|
||||
public EmailAddressAttribute() : base(default(System.ComponentModel.DataAnnotations.DataType)) { }
|
||||
public override bool IsValid(object value) { throw null; }
|
||||
}
|
||||
[System.AttributeUsageAttribute((System.AttributeTargets)(2496), AllowMultiple = false)]
|
||||
public sealed partial class EnumDataTypeAttribute : System.ComponentModel.DataAnnotations.DataTypeAttribute
|
||||
{
|
||||
public EnumDataTypeAttribute(System.Type enumType) : base(default(System.ComponentModel.DataAnnotations.DataType)) { }
|
||||
public System.Type EnumType { get { throw null; } }
|
||||
public override bool IsValid(object value) { throw null; }
|
||||
}
|
||||
[System.AttributeUsageAttribute((System.AttributeTargets)(2432), AllowMultiple = false)]
|
||||
public sealed partial class FileExtensionsAttribute : System.ComponentModel.DataAnnotations.DataTypeAttribute
|
||||
{
|
||||
public FileExtensionsAttribute() : base(default(System.ComponentModel.DataAnnotations.DataType)) { }
|
||||
public string Extensions { get { throw null; } set { } }
|
||||
public override string FormatErrorMessage(string name) { throw null; }
|
||||
public override bool IsValid(object value) { throw null; }
|
||||
}
|
||||
[System.AttributeUsageAttribute((System.AttributeTargets)(384), AllowMultiple = false)]
|
||||
[System.ObsoleteAttribute("This attribute is no longer in use and will be ignored if applied.")]
|
||||
public sealed partial class FilterUIHintAttribute : System.Attribute
|
||||
{
|
||||
public FilterUIHintAttribute(string filterUIHint) { }
|
||||
public FilterUIHintAttribute(string filterUIHint, string presentationLayer) { }
|
||||
public FilterUIHintAttribute(string filterUIHint, string presentationLayer, params object[] controlParameters) { }
|
||||
public System.Collections.Generic.IDictionary<string, object> ControlParameters { get { throw null; } }
|
||||
public string FilterUIHint { get { throw null; } }
|
||||
public string PresentationLayer { get { throw null; } }
|
||||
public override bool Equals(object obj) { throw null; }
|
||||
public override int GetHashCode() { throw null; }
|
||||
}
|
||||
public partial interface IValidatableObject
|
||||
{
|
||||
System.Collections.Generic.IEnumerable<System.ComponentModel.DataAnnotations.ValidationResult> Validate(System.ComponentModel.DataAnnotations.ValidationContext validationContext);
|
||||
}
|
||||
[System.AttributeUsageAttribute((System.AttributeTargets)(384), AllowMultiple = false, Inherited = true)]
|
||||
public sealed partial class KeyAttribute : System.Attribute
|
||||
{
|
||||
public KeyAttribute() { }
|
||||
}
|
||||
[System.AttributeUsageAttribute((System.AttributeTargets)(2432), AllowMultiple = false)]
|
||||
public partial class MaxLengthAttribute : System.ComponentModel.DataAnnotations.ValidationAttribute
|
||||
{
|
||||
public MaxLengthAttribute() { }
|
||||
public MaxLengthAttribute(int length) { }
|
||||
public int Length { get { throw null; } }
|
||||
public override string FormatErrorMessage(string name) { throw null; }
|
||||
public override bool IsValid(object value) { throw null; }
|
||||
}
|
||||
[System.AttributeUsageAttribute((System.AttributeTargets)(2432), AllowMultiple = false)]
|
||||
public partial class MinLengthAttribute : System.ComponentModel.DataAnnotations.ValidationAttribute
|
||||
{
|
||||
public MinLengthAttribute(int length) { }
|
||||
public int Length { get { throw null; } }
|
||||
public override string FormatErrorMessage(string name) { throw null; }
|
||||
public override bool IsValid(object value) { throw null; }
|
||||
}
|
||||
[System.AttributeUsageAttribute((System.AttributeTargets)(2432), AllowMultiple = false)]
|
||||
public sealed partial class PhoneAttribute : System.ComponentModel.DataAnnotations.DataTypeAttribute
|
||||
{
|
||||
public PhoneAttribute() : base(default(System.ComponentModel.DataAnnotations.DataType)) { }
|
||||
public override bool IsValid(object value) { throw null; }
|
||||
}
|
||||
[System.AttributeUsageAttribute((System.AttributeTargets)(2432), AllowMultiple = false)]
|
||||
public partial class RangeAttribute : System.ComponentModel.DataAnnotations.ValidationAttribute
|
||||
{
|
||||
public RangeAttribute(double minimum, double maximum) { }
|
||||
public RangeAttribute(int minimum, int maximum) { }
|
||||
public RangeAttribute(System.Type type, string minimum, string maximum) { }
|
||||
public object Maximum { get { throw null; } }
|
||||
public object Minimum { get { throw null; } }
|
||||
public System.Type OperandType { get { throw null; } }
|
||||
public override string FormatErrorMessage(string name) { throw null; }
|
||||
public override bool IsValid(object value) { throw null; }
|
||||
}
|
||||
[System.AttributeUsageAttribute((System.AttributeTargets)(2432), AllowMultiple = false)]
|
||||
public partial class RegularExpressionAttribute : System.ComponentModel.DataAnnotations.ValidationAttribute
|
||||
{
|
||||
public RegularExpressionAttribute(string pattern) { }
|
||||
public int MatchTimeoutInMilliseconds { get { throw null; } set { } }
|
||||
public string Pattern { get { throw null; } }
|
||||
public override string FormatErrorMessage(string name) { throw null; }
|
||||
public override bool IsValid(object value) { throw null; }
|
||||
}
|
||||
[System.AttributeUsageAttribute((System.AttributeTargets)(2432), AllowMultiple = false)]
|
||||
public partial class RequiredAttribute : System.ComponentModel.DataAnnotations.ValidationAttribute
|
||||
{
|
||||
public RequiredAttribute() { }
|
||||
public bool AllowEmptyStrings { get { throw null; } set { } }
|
||||
public override bool IsValid(object value) { throw null; }
|
||||
}
|
||||
[System.AttributeUsageAttribute((System.AttributeTargets)(384), AllowMultiple = false)]
|
||||
public partial class ScaffoldColumnAttribute : System.Attribute
|
||||
{
|
||||
public ScaffoldColumnAttribute(bool scaffold) { }
|
||||
public bool Scaffold { get { throw null; } }
|
||||
}
|
||||
[System.AttributeUsageAttribute((System.AttributeTargets)(2432), AllowMultiple = false)]
|
||||
public partial class StringLengthAttribute : System.ComponentModel.DataAnnotations.ValidationAttribute
|
||||
{
|
||||
public StringLengthAttribute(int maximumLength) { }
|
||||
public int MaximumLength { get { throw null; } }
|
||||
public int MinimumLength { get { throw null; } set { } }
|
||||
public override string FormatErrorMessage(string name) { throw null; }
|
||||
public override bool IsValid(object value) { throw null; }
|
||||
}
|
||||
[System.AttributeUsageAttribute((System.AttributeTargets)(384), AllowMultiple = false, Inherited = true)]
|
||||
public sealed partial class TimestampAttribute : System.Attribute
|
||||
{
|
||||
public TimestampAttribute() { }
|
||||
}
|
||||
[System.AttributeUsageAttribute((System.AttributeTargets)(384), AllowMultiple = true)]
|
||||
public partial class UIHintAttribute : System.Attribute
|
||||
{
|
||||
public UIHintAttribute(string uiHint) { }
|
||||
public UIHintAttribute(string uiHint, string presentationLayer) { }
|
||||
public UIHintAttribute(string uiHint, string presentationLayer, params object[] controlParameters) { }
|
||||
public System.Collections.Generic.IDictionary<string, object> ControlParameters { get { throw null; } }
|
||||
public string PresentationLayer { get { throw null; } }
|
||||
public string UIHint { get { throw null; } }
|
||||
public override bool Equals(object obj) { throw null; }
|
||||
public override int GetHashCode() { throw null; }
|
||||
}
|
||||
[System.AttributeUsageAttribute((System.AttributeTargets)(2432), AllowMultiple = false)]
|
||||
public sealed partial class UrlAttribute : System.ComponentModel.DataAnnotations.DataTypeAttribute
|
||||
{
|
||||
public UrlAttribute() : base(default(System.ComponentModel.DataAnnotations.DataType)) { }
|
||||
public override bool IsValid(object value) { throw null; }
|
||||
}
|
||||
public abstract partial class ValidationAttribute : System.Attribute
|
||||
{
|
||||
protected ValidationAttribute() { }
|
||||
protected ValidationAttribute(System.Func<string> errorMessageAccessor) { }
|
||||
protected ValidationAttribute(string errorMessage) { }
|
||||
public string ErrorMessage { get { throw null; } set { } }
|
||||
public string ErrorMessageResourceName { get { throw null; } set { } }
|
||||
public System.Type ErrorMessageResourceType { get { throw null; } set { } }
|
||||
protected string ErrorMessageString { get { throw null; } }
|
||||
public virtual bool RequiresValidationContext { get { throw null; } }
|
||||
public virtual string FormatErrorMessage(string name) { throw null; }
|
||||
public System.ComponentModel.DataAnnotations.ValidationResult GetValidationResult(object value, System.ComponentModel.DataAnnotations.ValidationContext validationContext) { throw null; }
|
||||
public virtual bool IsValid(object value) { throw null; }
|
||||
protected virtual System.ComponentModel.DataAnnotations.ValidationResult IsValid(object value, System.ComponentModel.DataAnnotations.ValidationContext validationContext) { throw null; }
|
||||
public void Validate(object value, System.ComponentModel.DataAnnotations.ValidationContext validationContext) { }
|
||||
public void Validate(object value, string name) { }
|
||||
}
|
||||
public sealed partial class ValidationContext : System.IServiceProvider
|
||||
{
|
||||
public ValidationContext(object instance) { }
|
||||
public ValidationContext(object instance, System.Collections.Generic.IDictionary<object, object> items) { }
|
||||
public ValidationContext(object instance, System.IServiceProvider serviceProvider, System.Collections.Generic.IDictionary<object, object> items) { }
|
||||
public string DisplayName { get { throw null; } set { } }
|
||||
public System.Collections.Generic.IDictionary<object, object> Items { get { throw null; } }
|
||||
public string MemberName { get { throw null; } set { } }
|
||||
public object ObjectInstance { get { throw null; } }
|
||||
public System.Type ObjectType { get { throw null; } }
|
||||
public object GetService(System.Type serviceType) { throw null; }
|
||||
public void InitializeServiceProvider(System.Func<System.Type, object> serviceProvider) { }
|
||||
}
|
||||
public partial class ValidationException : System.Exception
|
||||
{
|
||||
public ValidationException() { }
|
||||
public ValidationException(System.ComponentModel.DataAnnotations.ValidationResult validationResult, System.ComponentModel.DataAnnotations.ValidationAttribute validatingAttribute, object value) { }
|
||||
public ValidationException(string message) { }
|
||||
public ValidationException(string errorMessage, System.ComponentModel.DataAnnotations.ValidationAttribute validatingAttribute, object value) { }
|
||||
public ValidationException(string message, System.Exception innerException) { }
|
||||
protected ValidationException(System.Runtime.Serialization.SerializationInfo info, System.Runtime.Serialization.StreamingContext context) { }
|
||||
public System.ComponentModel.DataAnnotations.ValidationAttribute ValidationAttribute { get { throw null; } }
|
||||
public System.ComponentModel.DataAnnotations.ValidationResult ValidationResult { get { throw null; } }
|
||||
public object Value { get { throw null; } }
|
||||
}
|
||||
public partial class ValidationResult
|
||||
{
|
||||
public static readonly System.ComponentModel.DataAnnotations.ValidationResult Success;
|
||||
protected ValidationResult(System.ComponentModel.DataAnnotations.ValidationResult validationResult) { }
|
||||
public ValidationResult(string errorMessage) { }
|
||||
public ValidationResult(string errorMessage, System.Collections.Generic.IEnumerable<string> memberNames) { }
|
||||
public string ErrorMessage { get { throw null; } set { } }
|
||||
public System.Collections.Generic.IEnumerable<string> MemberNames { get { throw null; } }
|
||||
public override string ToString() { throw null; }
|
||||
}
|
||||
public static partial class Validator
|
||||
{
|
||||
public static bool TryValidateObject(object instance, System.ComponentModel.DataAnnotations.ValidationContext validationContext, System.Collections.Generic.ICollection<System.ComponentModel.DataAnnotations.ValidationResult> validationResults) { throw null; }
|
||||
public static bool TryValidateObject(object instance, System.ComponentModel.DataAnnotations.ValidationContext validationContext, System.Collections.Generic.ICollection<System.ComponentModel.DataAnnotations.ValidationResult> validationResults, bool validateAllProperties) { throw null; }
|
||||
public static bool TryValidateProperty(object value, System.ComponentModel.DataAnnotations.ValidationContext validationContext, System.Collections.Generic.ICollection<System.ComponentModel.DataAnnotations.ValidationResult> validationResults) { throw null; }
|
||||
public static bool TryValidateValue(object value, System.ComponentModel.DataAnnotations.ValidationContext validationContext, System.Collections.Generic.ICollection<System.ComponentModel.DataAnnotations.ValidationResult> validationResults, System.Collections.Generic.IEnumerable<System.ComponentModel.DataAnnotations.ValidationAttribute> validationAttributes) { throw null; }
|
||||
public static void ValidateObject(object instance, System.ComponentModel.DataAnnotations.ValidationContext validationContext) { }
|
||||
public static void ValidateObject(object instance, System.ComponentModel.DataAnnotations.ValidationContext validationContext, bool validateAllProperties) { }
|
||||
public static void ValidateProperty(object value, System.ComponentModel.DataAnnotations.ValidationContext validationContext) { }
|
||||
public static void ValidateValue(object value, System.ComponentModel.DataAnnotations.ValidationContext validationContext, System.Collections.Generic.IEnumerable<System.ComponentModel.DataAnnotations.ValidationAttribute> validationAttributes) { }
|
||||
}
|
||||
}
|
||||
namespace System.ComponentModel.DataAnnotations.Schema
|
||||
{
|
||||
[System.AttributeUsageAttribute((System.AttributeTargets)(384), AllowMultiple = false)]
|
||||
public partial class ColumnAttribute : System.Attribute
|
||||
{
|
||||
public ColumnAttribute() { }
|
||||
public ColumnAttribute(string name) { }
|
||||
public string Name { get { throw null; } }
|
||||
public int Order { get { throw null; } set { } }
|
||||
public string TypeName { get { throw null; } set { } }
|
||||
}
|
||||
[System.AttributeUsageAttribute((System.AttributeTargets)(4), AllowMultiple = false)]
|
||||
public partial class ComplexTypeAttribute : System.Attribute
|
||||
{
|
||||
public ComplexTypeAttribute() { }
|
||||
}
|
||||
[System.AttributeUsageAttribute((System.AttributeTargets)(384), AllowMultiple = false)]
|
||||
public partial class DatabaseGeneratedAttribute : System.Attribute
|
||||
{
|
||||
public DatabaseGeneratedAttribute(System.ComponentModel.DataAnnotations.Schema.DatabaseGeneratedOption databaseGeneratedOption) { }
|
||||
public System.ComponentModel.DataAnnotations.Schema.DatabaseGeneratedOption DatabaseGeneratedOption { get { throw null; } }
|
||||
}
|
||||
public enum DatabaseGeneratedOption
|
||||
{
|
||||
Computed = 2,
|
||||
Identity = 1,
|
||||
None = 0,
|
||||
}
|
||||
[System.AttributeUsageAttribute((System.AttributeTargets)(384), AllowMultiple = false)]
|
||||
public partial class ForeignKeyAttribute : System.Attribute
|
||||
{
|
||||
public ForeignKeyAttribute(string name) { }
|
||||
public string Name { get { throw null; } }
|
||||
}
|
||||
[System.AttributeUsageAttribute((System.AttributeTargets)(384), AllowMultiple = false)]
|
||||
public partial class InversePropertyAttribute : System.Attribute
|
||||
{
|
||||
public InversePropertyAttribute(string property) { }
|
||||
public string Property { get { throw null; } }
|
||||
}
|
||||
[System.AttributeUsageAttribute((System.AttributeTargets)(388), AllowMultiple = false)]
|
||||
public partial class NotMappedAttribute : System.Attribute
|
||||
{
|
||||
public NotMappedAttribute() { }
|
||||
}
|
||||
[System.AttributeUsageAttribute((System.AttributeTargets)(4), AllowMultiple = false)]
|
||||
public partial class TableAttribute : System.Attribute
|
||||
{
|
||||
public TableAttribute(string name) { }
|
||||
public string Name { get { throw null; } }
|
||||
public string Schema { get { throw null; } set { } }
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project ToolsVersion="14.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.props))\dir.props" />
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'netstandard-Debug|AnyCPU'" />
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'netstandard-Release|AnyCPU'" />
|
||||
<ItemGroup>
|
||||
<Compile Include="System.ComponentModel.Annotations.cs" />
|
||||
</ItemGroup>
|
||||
<Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.targets))\dir.targets" />
|
||||
</Project>
|
||||
9
external/corefx/src/System.ComponentModel.Annotations/src/Configurations.props
vendored
Normal file
9
external/corefx/src/System.ComponentModel.Annotations/src/Configurations.props
vendored
Normal file
@@ -0,0 +1,9 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project ToolsVersion="14.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<PropertyGroup>
|
||||
<BuildConfigurations>
|
||||
net463-Windows_NT;
|
||||
netstandard;
|
||||
</BuildConfigurations>
|
||||
</PropertyGroup>
|
||||
</Project>
|
||||
291
external/corefx/src/System.ComponentModel.Annotations/src/Resources/Strings.resx
vendored
Normal file
291
external/corefx/src/System.ComponentModel.Annotations/src/Resources/Strings.resx
vendored
Normal file
@@ -0,0 +1,291 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<root>
|
||||
<!--
|
||||
Microsoft ResX Schema
|
||||
|
||||
Version 2.0
|
||||
|
||||
The primary goals of this format is to allow a simple XML format
|
||||
that is mostly human readable. The generation and parsing of the
|
||||
various data types are done through the TypeConverter classes
|
||||
associated with the data types.
|
||||
|
||||
Example:
|
||||
|
||||
... ado.net/XML headers & schema ...
|
||||
<resheader name="resmimetype">text/microsoft-resx</resheader>
|
||||
<resheader name="version">2.0</resheader>
|
||||
<resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
|
||||
<resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
|
||||
<data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
|
||||
<data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
|
||||
<data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
|
||||
<value>[base64 mime encoded serialized .NET Framework object]</value>
|
||||
</data>
|
||||
<data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
|
||||
<value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
|
||||
<comment>This is a comment</comment>
|
||||
</data>
|
||||
|
||||
There are any number of "resheader" rows that contain simple
|
||||
name/value pairs.
|
||||
|
||||
Each data row contains a name, and value. The row also contains a
|
||||
type or mimetype. Type corresponds to a .NET class that support
|
||||
text/value conversion through the TypeConverter architecture.
|
||||
Classes that don't support this are serialized and stored with the
|
||||
mimetype set.
|
||||
|
||||
The mimetype is used for serialized objects, and tells the
|
||||
ResXResourceReader how to depersist the object. This is currently not
|
||||
extensible. For a given mimetype the value must be set accordingly:
|
||||
|
||||
Note - application/x-microsoft.net.object.binary.base64 is the format
|
||||
that the ResXResourceWriter will generate, however the reader can
|
||||
read any of the formats listed below.
|
||||
|
||||
mimetype: application/x-microsoft.net.object.binary.base64
|
||||
value : The object must be serialized with
|
||||
: System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
|
||||
: and then encoded with base64 encoding.
|
||||
|
||||
mimetype: application/x-microsoft.net.object.soap.base64
|
||||
value : The object must be serialized with
|
||||
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter
|
||||
: and then encoded with base64 encoding.
|
||||
|
||||
mimetype: application/x-microsoft.net.object.bytearray.base64
|
||||
value : The object must be serialized into a byte array
|
||||
: using a System.ComponentModel.TypeConverter
|
||||
: and then encoded with base64 encoding.
|
||||
-->
|
||||
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
|
||||
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
|
||||
<xsd:element name="root" msdata:IsDataSet="true">
|
||||
<xsd:complexType>
|
||||
<xsd:choice maxOccurs="unbounded">
|
||||
<xsd:element name="metadata">
|
||||
<xsd:complexType>
|
||||
<xsd:sequence>
|
||||
<xsd:element name="value" type="xsd:string" minOccurs="0" />
|
||||
</xsd:sequence>
|
||||
<xsd:attribute name="name" use="required" type="xsd:string" />
|
||||
<xsd:attribute name="type" type="xsd:string" />
|
||||
<xsd:attribute name="mimetype" type="xsd:string" />
|
||||
<xsd:attribute ref="xml:space" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
<xsd:element name="assembly">
|
||||
<xsd:complexType>
|
||||
<xsd:attribute name="alias" type="xsd:string" />
|
||||
<xsd:attribute name="name" type="xsd:string" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
<xsd:element name="data">
|
||||
<xsd:complexType>
|
||||
<xsd:sequence>
|
||||
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
|
||||
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
|
||||
</xsd:sequence>
|
||||
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
|
||||
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
|
||||
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
|
||||
<xsd:attribute ref="xml:space" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
<xsd:element name="resheader">
|
||||
<xsd:complexType>
|
||||
<xsd:sequence>
|
||||
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
|
||||
</xsd:sequence>
|
||||
<xsd:attribute name="name" type="xsd:string" use="required" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
</xsd:choice>
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
</xsd:schema>
|
||||
<resheader name="resmimetype">
|
||||
<value>text/microsoft-resx</value>
|
||||
</resheader>
|
||||
<resheader name="version">
|
||||
<value>2.0</value>
|
||||
</resheader>
|
||||
<resheader name="reader">
|
||||
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||
</resheader>
|
||||
<resheader name="writer">
|
||||
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||
</resheader>
|
||||
<data name="ArgumentIsNullOrWhitespace" xml:space="preserve">
|
||||
<value>The argument '{0}' cannot be null, empty or contain only white space.</value>
|
||||
</data>
|
||||
<data name="AssociatedMetadataTypeTypeDescriptor_MetadataTypeContainsUnknownProperties" xml:space="preserve">
|
||||
<value>The associated metadata type for type '{0}' contains the following unknown properties or fields: {1}. Please make sure that the names of these members match the names of the properties on the main type.</value>
|
||||
</data>
|
||||
<data name="AttributeStore_Type_Must_Be_Public" xml:space="preserve">
|
||||
<value>The type '{0}' must be public.</value>
|
||||
</data>
|
||||
<data name="AttributeStore_Unknown_Method" xml:space="preserve">
|
||||
<value>The type '{0}' does not contain a public method named '{1}'.</value>
|
||||
</data>
|
||||
<data name="AttributeStore_Unknown_Property" xml:space="preserve">
|
||||
<value>The type '{0}' does not contain a public property named '{1}'.</value>
|
||||
</data>
|
||||
<data name="Common_NullOrEmpty" xml:space="preserve">
|
||||
<value>Value cannot be null or empty.</value>
|
||||
</data>
|
||||
<data name="Common_PropertyNotFound" xml:space="preserve">
|
||||
<value>The property {0}.{1} could not be found.</value>
|
||||
</data>
|
||||
<data name="CompareAttribute_MustMatch" xml:space="preserve">
|
||||
<value>'{0}' and '{1}' do not match.</value>
|
||||
</data>
|
||||
<data name="CompareAttribute_UnknownProperty" xml:space="preserve">
|
||||
<value>Could not find a property named {0}.</value>
|
||||
</data>
|
||||
<data name="CreditCardAttribute_Invalid" xml:space="preserve">
|
||||
<value>The {0} field is not a valid credit card number.</value>
|
||||
</data>
|
||||
<data name="CustomValidationAttribute_Method_Must_Return_ValidationResult" xml:space="preserve">
|
||||
<value>The CustomValidationAttribute method '{0}' in type '{1}' must return System.ComponentModel.DataAnnotations.ValidationResult. Use System.ComponentModel.DataAnnotations.ValidationResult.Success to represent success.</value>
|
||||
</data>
|
||||
<data name="CustomValidationAttribute_Method_Not_Found" xml:space="preserve">
|
||||
<value>The CustomValidationAttribute method '{0}' does not exist in type '{1}' or is not public and static.</value>
|
||||
</data>
|
||||
<data name="CustomValidationAttribute_Method_Required" xml:space="preserve">
|
||||
<value>The CustomValidationAttribute.Method was not specified.</value>
|
||||
</data>
|
||||
<data name="CustomValidationAttribute_Method_Signature" xml:space="preserve">
|
||||
<value>The CustomValidationAttribute method '{0}' in type '{1}' must match the expected signature: public static ValidationResult {0}(object value, ValidationContext context). The value can be strongly typed. The ValidationContext parameter is optional.</value>
|
||||
</data>
|
||||
<data name="CustomValidationAttribute_Type_Conversion_Failed" xml:space="preserve">
|
||||
<value>Could not convert the value of type '{0}' to '{1}' as expected by method {2}.{3}.</value>
|
||||
</data>
|
||||
<data name="CustomValidationAttribute_Type_Must_Be_Public" xml:space="preserve">
|
||||
<value>The custom validation type '{0}' must be public.</value>
|
||||
</data>
|
||||
<data name="CustomValidationAttribute_ValidationError" xml:space="preserve">
|
||||
<value>{0} is not valid.</value>
|
||||
</data>
|
||||
<data name="CustomValidationAttribute_ValidatorType_Required" xml:space="preserve">
|
||||
<value>The CustomValidationAttribute.ValidatorType was not specified.</value>
|
||||
</data>
|
||||
<data name="DataTypeAttribute_EmptyDataTypeString" xml:space="preserve">
|
||||
<value>The custom DataType string cannot be null or empty.</value>
|
||||
</data>
|
||||
<data name="DisplayAttribute_PropertyNotSet" xml:space="preserve">
|
||||
<value>The {0} property has not been set. Use the {1} method to get the value.</value>
|
||||
</data>
|
||||
<data name="EmailAddressAttribute_Invalid" xml:space="preserve">
|
||||
<value>The {0} field is not a valid e-mail address.</value>
|
||||
</data>
|
||||
<data name="EnumDataTypeAttribute_TypeCannotBeNull" xml:space="preserve">
|
||||
<value>The type provided for EnumDataTypeAttribute cannot be null.</value>
|
||||
</data>
|
||||
<data name="EnumDataTypeAttribute_TypeNeedsToBeAnEnum" xml:space="preserve">
|
||||
<value>The type '{0}' needs to represent an enumeration type.</value>
|
||||
</data>
|
||||
<data name="FileExtensionsAttribute_Invalid" xml:space="preserve">
|
||||
<value>The {0} field only accepts files with the following extensions: {1}</value>
|
||||
</data>
|
||||
<data name="LocalizableString_LocalizationFailed" xml:space="preserve">
|
||||
<value>Cannot retrieve property '{0}' because localization failed. Type '{1}' is not public or does not contain a public static string property with the name '{2}'.</value>
|
||||
</data>
|
||||
<data name="MaxLengthAttribute_InvalidMaxLength" xml:space="preserve">
|
||||
<value>MaxLengthAttribute must have a Length value that is greater than zero. Use MaxLength() without parameters to indicate that the string or array can have the maximum allowable length.</value>
|
||||
</data>
|
||||
<data name="MaxLengthAttribute_ValidationError" xml:space="preserve">
|
||||
<value>The field {0} must be a string or array type with a maximum length of '{1}'.</value>
|
||||
</data>
|
||||
<data name="MetadataTypeAttribute_TypeCannotBeNull" xml:space="preserve">
|
||||
<value>MetadataClassType cannot be null.</value>
|
||||
</data>
|
||||
<data name="MinLengthAttribute_InvalidMinLength" xml:space="preserve">
|
||||
<value>MinLengthAttribute must have a Length value that is zero or greater.</value>
|
||||
</data>
|
||||
<data name="MinLengthAttribute_ValidationError" xml:space="preserve">
|
||||
<value>The field {0} must be a string or array type with a minimum length of '{1}'.</value>
|
||||
</data>
|
||||
<data name="PhoneAttribute_Invalid" xml:space="preserve">
|
||||
<value>The {0} field is not a valid phone number.</value>
|
||||
</data>
|
||||
<data name="RangeAttribute_ArbitraryTypeNotIComparable" xml:space="preserve">
|
||||
<value>The type {0} must implement {1}.</value>
|
||||
</data>
|
||||
<data name="RangeAttribute_MinGreaterThanMax" xml:space="preserve">
|
||||
<value>The maximum value '{0}' must be greater than or equal to the minimum value '{1}'.</value>
|
||||
</data>
|
||||
<data name="RangeAttribute_Must_Set_Min_And_Max" xml:space="preserve">
|
||||
<value>The minimum and maximum values must be set.</value>
|
||||
</data>
|
||||
<data name="RangeAttribute_Must_Set_Operand_Type" xml:space="preserve">
|
||||
<value>The OperandType must be set when strings are used for minimum and maximum values.</value>
|
||||
</data>
|
||||
<data name="RangeAttribute_ValidationError" xml:space="preserve">
|
||||
<value>The field {0} must be between {1} and {2}.</value>
|
||||
</data>
|
||||
<data name="RegexAttribute_ValidationError" xml:space="preserve">
|
||||
<value>The field {0} must match the regular expression '{1}'.</value>
|
||||
</data>
|
||||
<data name="RegularExpressionAttribute_Empty_Pattern" xml:space="preserve">
|
||||
<value>The pattern must be set to a valid regular expression.</value>
|
||||
</data>
|
||||
<data name="RequiredAttribute_ValidationError" xml:space="preserve">
|
||||
<value>The {0} field is required.</value>
|
||||
</data>
|
||||
<data name="StringLengthAttribute_InvalidMaxLength" xml:space="preserve">
|
||||
<value>The maximum length must be a nonnegative integer.</value>
|
||||
</data>
|
||||
<data name="StringLengthAttribute_ValidationError" xml:space="preserve">
|
||||
<value>The field {0} must be a string with a maximum length of {1}.</value>
|
||||
</data>
|
||||
<data name="StringLengthAttribute_ValidationErrorIncludingMinimum" xml:space="preserve">
|
||||
<value>The field {0} must be a string with a minimum length of {2} and a maximum length of {1}.</value>
|
||||
</data>
|
||||
<data name="UIHintImplementation_ControlParameterKeyIsNotAString" xml:space="preserve">
|
||||
<value>The key parameter at position {0} with value '{1}' is not a string. Every key control parameter must be a string.</value>
|
||||
</data>
|
||||
<data name="UIHintImplementation_ControlParameterKeyIsNull" xml:space="preserve">
|
||||
<value>The key parameter at position {0} is null. Every key control parameter must be a string.</value>
|
||||
</data>
|
||||
<data name="UIHintImplementation_ControlParameterKeyOccursMoreThanOnce" xml:space="preserve">
|
||||
<value>The key parameter at position {0} with value '{1}' occurs more than once.</value>
|
||||
</data>
|
||||
<data name="UIHintImplementation_NeedEvenNumberOfControlParameters" xml:space="preserve">
|
||||
<value>The number of control parameters must be even.</value>
|
||||
</data>
|
||||
<data name="UrlAttribute_Invalid" xml:space="preserve">
|
||||
<value>The {0} field is not a valid fully-qualified http, https, or ftp URL.</value>
|
||||
</data>
|
||||
<data name="ValidationAttribute_Cannot_Set_ErrorMessage_And_Resource" xml:space="preserve">
|
||||
<value>Either ErrorMessageString or ErrorMessageResourceName must be set, but not both.</value>
|
||||
</data>
|
||||
<data name="ValidationAttribute_IsValid_NotImplemented" xml:space="preserve">
|
||||
<value>IsValid(object value) has not been implemented by this class. The preferred entry point is GetValidationResult() and classes should override IsValid(object value, ValidationContext context).</value>
|
||||
</data>
|
||||
<data name="ValidationAttribute_NeedBothResourceTypeAndResourceName" xml:space="preserve">
|
||||
<value>Both ErrorMessageResourceType and ErrorMessageResourceName need to be set on this attribute.</value>
|
||||
</data>
|
||||
<data name="ValidationAttribute_ResourcePropertyNotStringType" xml:space="preserve">
|
||||
<value>The property '{0}' on resource type '{1}' is not a string type.</value>
|
||||
</data>
|
||||
<data name="ValidationAttribute_ResourceTypeDoesNotHaveProperty" xml:space="preserve">
|
||||
<value>The resource type '{0}' does not have an accessible static property named '{1}'.</value>
|
||||
</data>
|
||||
<data name="ValidationAttribute_ValidationError" xml:space="preserve">
|
||||
<value>The field {0} is invalid.</value>
|
||||
</data>
|
||||
<data name="ValidationContext_Must_Be_Method" xml:space="preserve">
|
||||
<value>The ValidationContext for the type '{0}', member name '{1}' must provide the MethodInfo.</value>
|
||||
</data>
|
||||
<data name="ValidationContextServiceContainer_ItemAlreadyExists" xml:space="preserve">
|
||||
<value>A service of type '{0}' already exists in the container.</value>
|
||||
</data>
|
||||
<data name="Validator_InstanceMustMatchValidationContextInstance" xml:space="preserve">
|
||||
<value>The instance provided must match the ObjectInstance on the ValidationContext supplied.</value>
|
||||
</data>
|
||||
<data name="Validator_Property_Value_Wrong_Type" xml:space="preserve">
|
||||
<value>The value for property '{0}' must be of type '{1}'.</value>
|
||||
</data>
|
||||
</root>
|
||||
@@ -0,0 +1,68 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project ToolsVersion="14.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.props))\dir.props" />
|
||||
<PropertyGroup>
|
||||
<ProjectGuid>{4266D58F-EB60-46C2-BA81-3ABDE759A7D5}</ProjectGuid>
|
||||
<RootNamespace>System.ComponentModel.Annotations</RootNamespace>
|
||||
<AssemblyName>System.ComponentModel.Annotations</AssemblyName>
|
||||
<IsPartialFacadeAssembly Condition="'$(TargetGroup)'=='net463'">true</IsPartialFacadeAssembly>
|
||||
</PropertyGroup>
|
||||
<!-- Default configurations to help VS understand the options -->
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='net463-Windows_NT-Debug|AnyCPU'" />
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='net463-Windows_NT-Release|AnyCPU'" />
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='netstandard-Debug|AnyCPU'" />
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='netstandard-Release|AnyCPU'" />
|
||||
<ItemGroup Condition="'$(TargetGroup)'=='netstandard'">
|
||||
<Compile Include="System\ComponentModel\DataAnnotations\AssociationAttribute.cs" />
|
||||
<Compile Include="System\ComponentModel\DataAnnotations\CompareAttribute.cs" />
|
||||
<Compile Include="System\ComponentModel\DataAnnotations\ConcurrencyCheckAttribute.cs" />
|
||||
<Compile Include="System\ComponentModel\DataAnnotations\CreditCardAttribute.cs" />
|
||||
<Compile Include="System\ComponentModel\DataAnnotations\CustomValidationAttribute.cs" />
|
||||
<Compile Include="System\ComponentModel\DataAnnotations\DataType.cs" />
|
||||
<Compile Include="System\ComponentModel\DataAnnotations\DataTypeAttribute.cs" />
|
||||
<Compile Include="System\ComponentModel\DataAnnotations\DisplayAttribute.cs" />
|
||||
<Compile Include="System\ComponentModel\DataAnnotations\DisplayColumnAttribute.cs" />
|
||||
<Compile Include="System\ComponentModel\DataAnnotations\DisplayFormatAttribute.cs" />
|
||||
<Compile Include="System\ComponentModel\DataAnnotations\EditableAttribute.cs" />
|
||||
<Compile Include="System\ComponentModel\DataAnnotations\EmailAddressAttribute.cs" />
|
||||
<Compile Include="System\ComponentModel\DataAnnotations\EnumDataTypeAttribute.cs" />
|
||||
<Compile Include="System\ComponentModel\DataAnnotations\FileExtensionsAttribute.cs" />
|
||||
<Compile Include="System\ComponentModel\DataAnnotations\FilterUIHintAttribute.cs" />
|
||||
<Compile Include="System\ComponentModel\DataAnnotations\IValidatableObject.cs" />
|
||||
<Compile Include="System\ComponentModel\DataAnnotations\KeyAttribute.cs" />
|
||||
<Compile Include="System\ComponentModel\DataAnnotations\LocalizableString.cs" />
|
||||
<Compile Include="System\ComponentModel\DataAnnotations\MaxLengthAttribute.cs" />
|
||||
<Compile Include="System\ComponentModel\DataAnnotations\MinLengthAttribute.cs" />
|
||||
<Compile Include="System\ComponentModel\DataAnnotations\PhoneAttribute.cs" />
|
||||
<Compile Include="System\ComponentModel\DataAnnotations\RangeAttribute.cs" />
|
||||
<Compile Include="System\ComponentModel\DataAnnotations\RegularExpressionAttribute.cs" />
|
||||
<Compile Include="System\ComponentModel\DataAnnotations\RequiredAttribute.cs" />
|
||||
<Compile Include="System\ComponentModel\DataAnnotations\ScaffoldColumnAttribute.cs" />
|
||||
<Compile Include="System\ComponentModel\DataAnnotations\Schema\ColumnAttribute.cs" />
|
||||
<Compile Include="System\ComponentModel\DataAnnotations\Schema\ComplexTypeAttribute.cs" />
|
||||
<Compile Include="System\ComponentModel\DataAnnotations\Schema\DatabaseGeneratedAttribute.cs" />
|
||||
<Compile Include="System\ComponentModel\DataAnnotations\Schema\DatabaseGeneratedOption.cs" />
|
||||
<Compile Include="System\ComponentModel\DataAnnotations\Schema\ForeignKeyAttribute.cs" />
|
||||
<Compile Include="System\ComponentModel\DataAnnotations\Schema\InversePropertyAttribute.cs" />
|
||||
<Compile Include="System\ComponentModel\DataAnnotations\Schema\NotMappedAttribute.cs" />
|
||||
<Compile Include="System\ComponentModel\DataAnnotations\Schema\TableAttribute.cs" />
|
||||
<Compile Include="System\ComponentModel\DataAnnotations\StringLengthAttribute.cs" />
|
||||
<Compile Include="System\ComponentModel\DataAnnotations\TimestampAttribute.cs" />
|
||||
<Compile Include="System\ComponentModel\DataAnnotations\UIHintAttribute.cs" />
|
||||
<Compile Include="System\ComponentModel\DataAnnotations\UrlAttribute.cs" />
|
||||
<Compile Include="System\ComponentModel\DataAnnotations\ValidationAttribute.cs" />
|
||||
<Compile Include="System\ComponentModel\DataAnnotations\ValidationAttributeStore.cs" />
|
||||
<Compile Include="System\ComponentModel\DataAnnotations\ValidationContext.cs" />
|
||||
<Compile Include="System\ComponentModel\DataAnnotations\ValidationException.cs" />
|
||||
<Compile Include="System\ComponentModel\DataAnnotations\ValidationResult.cs" />
|
||||
<Compile Include="System\ComponentModel\DataAnnotations\Validator.cs" />
|
||||
<Compile Include="$(CommonPath)\System\NotImplemented.cs">
|
||||
<Link>Common\System\NotImplemented.cs</Link>
|
||||
</Compile>
|
||||
</ItemGroup>
|
||||
<ItemGroup Condition="'$(TargetGroup)'=='net463'">
|
||||
<TargetingPackReference Include="mscorlib" />
|
||||
<TargetingPackReference Include="System.ComponentModel.DataAnnotations" />
|
||||
</ItemGroup>
|
||||
<Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.targets))\dir.targets" />
|
||||
</Project>
|
||||
@@ -0,0 +1,107 @@
|
||||
// Licensed to the .NET Foundation under one or more agreements.
|
||||
// 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.Generic;
|
||||
|
||||
namespace System.ComponentModel.DataAnnotations
|
||||
{
|
||||
/// <summary>
|
||||
/// Used to mark an Entity member as an association
|
||||
/// </summary>
|
||||
[AttributeUsage(AttributeTargets.Field | AttributeTargets.Property, AllowMultiple = false,
|
||||
Inherited = true)]
|
||||
[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>
|
||||
/// <param name="name">The name of the association. For bi-directional associations,
|
||||
/// the name must be the same on both sides of the association</param>
|
||||
/// <param name="thisKey">Comma separated list of the property names of the key values
|
||||
/// on this side of the association</param>
|
||||
/// <param name="otherKey">Comma separated list of the property names of the key values
|
||||
/// on the other side of the association</param>
|
||||
public AssociationAttribute(string name, string thisKey, string 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; }
|
||||
}
|
||||
|
||||
/// <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; }
|
||||
}
|
||||
|
||||
/// <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; }
|
||||
}
|
||||
|
||||
/// <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; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the collection of individual key members specified in the ThisKey string.
|
||||
/// </summary>
|
||||
public IEnumerable<string> ThisKeyMembers
|
||||
{
|
||||
get
|
||||
{
|
||||
return GetKeyMembers(ThisKey);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the collection of individual key members specified in the OtherKey string.
|
||||
/// </summary>
|
||||
public IEnumerable<string> OtherKeyMembers
|
||||
{
|
||||
get
|
||||
{
|
||||
return 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(',');
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,93 @@
|
||||
// Licensed to the .NET Foundation under one or more agreements.
|
||||
// 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.Globalization;
|
||||
using System.Linq;
|
||||
using System.Reflection;
|
||||
|
||||
namespace System.ComponentModel.DataAnnotations
|
||||
{
|
||||
[AttributeUsage(AttributeTargets.Property, AllowMultiple = false)]
|
||||
public class CompareAttribute : ValidationAttribute
|
||||
{
|
||||
public CompareAttribute(string otherProperty)
|
||||
: base(SR.CompareAttribute_MustMatch)
|
||||
{
|
||||
if (otherProperty == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(otherProperty));
|
||||
}
|
||||
OtherProperty = otherProperty;
|
||||
}
|
||||
|
||||
public string OtherProperty { get; private set; }
|
||||
|
||||
public string OtherPropertyDisplayName { get; internal set; }
|
||||
|
||||
public override bool RequiresValidationContext
|
||||
{
|
||||
get { return true; }
|
||||
}
|
||||
|
||||
public override string FormatErrorMessage(string name)
|
||||
{
|
||||
return string.Format(CultureInfo.CurrentCulture, ErrorMessageString, name,
|
||||
OtherPropertyDisplayName ?? OtherProperty);
|
||||
}
|
||||
|
||||
protected override ValidationResult IsValid(object value, ValidationContext validationContext)
|
||||
{
|
||||
// TODO - check that GetRuntimeProperty() returns the same as old ObjectType.GetProperty()
|
||||
// in all situations regardless of property modifiers
|
||||
var otherPropertyInfo = validationContext.ObjectType.GetRuntimeProperty(OtherProperty);
|
||||
if (otherPropertyInfo == null)
|
||||
{
|
||||
return
|
||||
new ValidationResult(string.Format(CultureInfo.CurrentCulture,
|
||||
SR.CompareAttribute_UnknownProperty, OtherProperty));
|
||||
}
|
||||
|
||||
object otherPropertyValue = otherPropertyInfo.GetValue(validationContext.ObjectInstance, null);
|
||||
if (!Equals(value, otherPropertyValue))
|
||||
{
|
||||
if (OtherPropertyDisplayName == null)
|
||||
{
|
||||
OtherPropertyDisplayName = GetDisplayNameForProperty(validationContext.ObjectType, OtherProperty);
|
||||
}
|
||||
return new ValidationResult(FormatErrorMessage(validationContext.DisplayName));
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
private static string GetDisplayNameForProperty(Type containerType, string propertyName)
|
||||
{
|
||||
var property = containerType.GetRuntimeProperties()
|
||||
.SingleOrDefault(
|
||||
prop =>
|
||||
IsPublic(prop) &&
|
||||
string.Equals(propertyName, prop.Name, StringComparison.OrdinalIgnoreCase) &&
|
||||
!prop.GetIndexParameters().Any());
|
||||
|
||||
if (property == null)
|
||||
{
|
||||
throw new ArgumentException(string.Format(CultureInfo.CurrentCulture,
|
||||
SR.Common_PropertyNotFound, containerType.FullName, propertyName));
|
||||
}
|
||||
|
||||
var attributes = CustomAttributeExtensions.GetCustomAttributes(property, true);
|
||||
var display = attributes.OfType<DisplayAttribute>().FirstOrDefault();
|
||||
if (display != null)
|
||||
{
|
||||
return display.GetName();
|
||||
}
|
||||
|
||||
return propertyName;
|
||||
}
|
||||
|
||||
private static bool IsPublic(PropertyInfo p)
|
||||
{
|
||||
return (p.GetMethod != null && p.GetMethod.IsPublic) || (p.SetMethod != null && p.SetMethod.IsPublic);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
// Licensed to the .NET Foundation under one or more agreements.
|
||||
// The .NET Foundation licenses this file to you under the MIT license.
|
||||
// See the LICENSE file in the project root for more information.
|
||||
|
||||
namespace System.ComponentModel.DataAnnotations
|
||||
{
|
||||
/// <summary>
|
||||
/// This attribute is used to mark the members of a Type that participate in
|
||||
/// optimistic concurrency checks.
|
||||
/// </summary>
|
||||
[AttributeUsage(AttributeTargets.Property | AttributeTargets.Field, AllowMultiple = false, Inherited = true)]
|
||||
public sealed class ConcurrencyCheckAttribute : Attribute
|
||||
{
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,59 @@
|
||||
// Licensed to the .NET Foundation under one or more agreements.
|
||||
// The .NET Foundation licenses this file to you under the MIT license.
|
||||
// See the LICENSE file in the project root for more information.
|
||||
|
||||
namespace System.ComponentModel.DataAnnotations
|
||||
{
|
||||
[AttributeUsage(AttributeTargets.Property | AttributeTargets.Field | AttributeTargets.Parameter,
|
||||
AllowMultiple = false)]
|
||||
public sealed class CreditCardAttribute : DataTypeAttribute
|
||||
{
|
||||
public CreditCardAttribute()
|
||||
: base(DataType.CreditCard)
|
||||
{
|
||||
// Set DefaultErrorMessage, allowing user to set
|
||||
// ErrorMessageResourceType and ErrorMessageResourceName to use localized messages.
|
||||
DefaultErrorMessage = SR.CreditCardAttribute_Invalid;
|
||||
}
|
||||
|
||||
public override bool IsValid(object value)
|
||||
{
|
||||
if (value == null)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
var ccValue = value as string;
|
||||
if (ccValue == null)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
ccValue = ccValue.Replace("-", string.Empty);
|
||||
ccValue = ccValue.Replace(" ", string.Empty);
|
||||
|
||||
var checksum = 0;
|
||||
var evenDigit = false;
|
||||
|
||||
// Note: string.Reverse() does not exist for WinPhone
|
||||
for (var i = ccValue.Length - 1; i >= 0; i--)
|
||||
{
|
||||
var digit = ccValue[i];
|
||||
if (digit < '0' || digit > '9')
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
var digitValue = (digit - '0') * (evenDigit ? 2 : 1);
|
||||
evenDigit = !evenDigit;
|
||||
|
||||
while (digitValue > 0)
|
||||
{
|
||||
checksum += digitValue % 10;
|
||||
digitValue /= 10;
|
||||
}
|
||||
}
|
||||
|
||||
return (checksum % 10) == 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,368 @@
|
||||
// Licensed to the .NET Foundation under one or more agreements.
|
||||
// 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.Globalization;
|
||||
using System.Linq;
|
||||
using System.Reflection;
|
||||
|
||||
namespace System.ComponentModel.DataAnnotations
|
||||
{
|
||||
/// <summary>
|
||||
/// Validation attribute that executes a user-supplied method at runtime, using one of these signatures:
|
||||
/// <para>
|
||||
/// public static <see cref="ValidationResult" /> Method(object value) { ... }
|
||||
/// </para>
|
||||
/// <para>
|
||||
/// public static <see cref="ValidationResult" /> Method(object value, <see cref="ValidationContext" /> context) {
|
||||
/// ... }
|
||||
/// </para>
|
||||
/// <para>
|
||||
/// The value can be strongly typed as type conversion will be attempted.
|
||||
/// </para>
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// This validation attribute is used to invoke custom logic to perform validation at runtime.
|
||||
/// Like any other <see cref="ValidationAttribute" />, its <see cref="IsValid(object, ValidationContext)" />
|
||||
/// method is invoked to perform validation. This implementation simply redirects that call to the method
|
||||
/// identified by <see cref="Method" /> on a type identified by <see cref="ValidatorType" />
|
||||
/// <para>
|
||||
/// The supplied <see cref="ValidatorType" /> cannot be null, and it must be a public type.
|
||||
/// </para>
|
||||
/// <para>
|
||||
/// The named <see cref="Method" /> must be public, static, return <see cref="ValidationResult" /> and take at
|
||||
/// least one input parameter for the value to be validated. This value parameter may be strongly typed.
|
||||
/// Type conversion will be attempted if clients pass in a value of a different type.
|
||||
/// </para>
|
||||
/// <para>
|
||||
/// The <see cref="Method" /> may also declare an additional parameter of type <see cref="ValidationContext" />.
|
||||
/// The <see cref="ValidationContext" /> parameter provides additional context the method may use to determine
|
||||
/// the context in which it is being used.
|
||||
/// </para>
|
||||
/// <para>
|
||||
/// If the method returns <see cref="ValidationResult" />.<see cref="ValidationResult.Success" />, that indicates
|
||||
/// the given value is acceptable and validation passed.
|
||||
/// Returning an instance of <see cref="ValidationResult" /> indicates that the value is not acceptable
|
||||
/// and validation failed.
|
||||
/// </para>
|
||||
/// <para>
|
||||
/// If the method returns a <see cref="ValidationResult" /> with a <c>null</c>
|
||||
/// <see cref="ValidationResult.ErrorMessage" />
|
||||
/// then the normal <see cref="ValidationAttribute.FormatErrorMessage" /> method will be called to compose the
|
||||
/// error message.
|
||||
/// </para>
|
||||
/// </remarks>
|
||||
[AttributeUsage(
|
||||
AttributeTargets.Class | AttributeTargets.Property | AttributeTargets.Field | AttributeTargets.Method |
|
||||
AttributeTargets.Parameter, AllowMultiple = true)]
|
||||
public sealed class CustomValidationAttribute : ValidationAttribute
|
||||
{
|
||||
#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;
|
||||
private Type _firstParameterType;
|
||||
|
||||
#endregion
|
||||
|
||||
#region All Constructors
|
||||
|
||||
/// <summary>
|
||||
/// Instantiates a custom validation attribute that will invoke a method in the
|
||||
/// specified type.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// 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>
|
||||
/// <param name="validatorType">
|
||||
/// The type that will contain the method to invoke. It cannot be null. See
|
||||
/// <see cref="Method" />.
|
||||
/// </param>
|
||||
/// <param name="method">The name of the method to invoke in <paramref name="validatorType" />.</param>
|
||||
public CustomValidationAttribute(Type validatorType, string method)
|
||||
: base(() => SR.CustomValidationAttribute_ValidationError)
|
||||
{
|
||||
_validatorType = validatorType;
|
||||
_method = method;
|
||||
_malformedErrorMessage = new Lazy<string>(CheckAttributeWellFormed);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Properties
|
||||
|
||||
/// <summary>
|
||||
/// Gets the type that contains the validation method identified by <see cref="Method" />.
|
||||
/// </summary>
|
||||
public Type ValidatorType
|
||||
{
|
||||
get { return _validatorType; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the name of the method in <see cref="ValidatorType" /> to invoke to perform validation.
|
||||
/// </summary>
|
||||
public string Method
|
||||
{
|
||||
get { return _method; }
|
||||
}
|
||||
|
||||
public override bool RequiresValidationContext
|
||||
{
|
||||
get
|
||||
{
|
||||
// If attribute is not valid, throw an exception right away to inform the developer
|
||||
ThrowIfAttributeNotWellFormed();
|
||||
// We should return true when 2-parameter form of the validation method is used
|
||||
return !_isSingleArgumentMethod;
|
||||
}
|
||||
}
|
||||
#endregion
|
||||
|
||||
/// <summary>
|
||||
/// Override of validation method. See <see cref="ValidationAttribute.IsValid(object, ValidationContext)" />.
|
||||
/// </summary>
|
||||
/// <param name="value">The value to validate.</param>
|
||||
/// <param name="validationContext">
|
||||
/// A <see cref="ValidationContext" /> instance that provides
|
||||
/// context about the validation operation, such as the object and member being validated.
|
||||
/// </param>
|
||||
/// <returns>Whatever the <see cref="Method" /> in <see cref="ValidatorType" /> returns.</returns>
|
||||
/// <exception cref="InvalidOperationException"> is thrown if the current attribute is malformed.</exception>
|
||||
protected override ValidationResult IsValid(object value, ValidationContext validationContext)
|
||||
{
|
||||
// If attribute is not valid, throw an exception right away to inform the developer
|
||||
ThrowIfAttributeNotWellFormed();
|
||||
|
||||
var methodInfo = _methodInfo;
|
||||
|
||||
// If the value is not of the correct type and cannot be converted, fail
|
||||
// to indicate it is not acceptable. The convention is that IsValid is merely a probe,
|
||||
// and clients are not expecting exceptions.
|
||||
object convertedValue;
|
||||
if (!TryConvertValue(value, out convertedValue))
|
||||
{
|
||||
return
|
||||
new ValidationResult(
|
||||
string.Format(CultureInfo.CurrentCulture,
|
||||
SR.CustomValidationAttribute_Type_Conversion_Failed,
|
||||
(value != null ? value.GetType().ToString() : "null"),
|
||||
_firstParameterType,
|
||||
_validatorType,
|
||||
_method));
|
||||
}
|
||||
|
||||
// Invoke the method. Catch TargetInvocationException merely to unwrap it.
|
||||
// Callers don't know Reflection is being used and will not typically see
|
||||
// the real exception
|
||||
try
|
||||
{
|
||||
// 1-parameter form is ValidationResult Method(object value)
|
||||
// 2-parameter form is ValidationResult Method(object value, ValidationContext context),
|
||||
var methodParams = _isSingleArgumentMethod
|
||||
? new object[] { convertedValue }
|
||||
: new[] { convertedValue, validationContext };
|
||||
|
||||
var result = (ValidationResult)methodInfo.Invoke(null, methodParams);
|
||||
|
||||
// We capture the message they provide us only in the event of failure,
|
||||
// otherwise we use the normal message supplied via the ctor
|
||||
_lastMessage = null;
|
||||
|
||||
if (result != null)
|
||||
{
|
||||
_lastMessage = result.ErrorMessage;
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
catch (TargetInvocationException tie)
|
||||
{
|
||||
if (tie.InnerException != null)
|
||||
{
|
||||
throw tie.InnerException;
|
||||
}
|
||||
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Override of <see cref="ValidationAttribute.FormatErrorMessage" />
|
||||
/// </summary>
|
||||
/// <param name="name">The name to include in the formatted string</param>
|
||||
/// <returns>A localized string to describe the problem.</returns>
|
||||
/// <exception cref="InvalidOperationException"> is thrown if the current attribute is malformed.</exception>
|
||||
public override string FormatErrorMessage(string name)
|
||||
{
|
||||
// If attribute is not valid, throw an exception right away to inform the developer
|
||||
ThrowIfAttributeNotWellFormed();
|
||||
|
||||
if (!string.IsNullOrEmpty(_lastMessage))
|
||||
{
|
||||
return string.Format(CultureInfo.CurrentCulture, _lastMessage, name);
|
||||
}
|
||||
|
||||
// If success or they supplied no custom message, use normal base class behavior
|
||||
return base.FormatErrorMessage(name);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 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();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Internal helper to determine whether <see cref="ValidatorType" /> is legal for use.
|
||||
/// </summary>
|
||||
/// <returns><c>null</c> or the appropriate error message.</returns>
|
||||
private string ValidateValidatorTypeParameter()
|
||||
{
|
||||
if (_validatorType == null)
|
||||
{
|
||||
return SR.CustomValidationAttribute_ValidatorType_Required;
|
||||
}
|
||||
|
||||
if (!_validatorType.GetTypeInfo().IsVisible)
|
||||
{
|
||||
return string.Format(CultureInfo.CurrentCulture,
|
||||
SR.CustomValidationAttribute_Type_Must_Be_Public, _validatorType.Name);
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Internal helper to determine whether <see cref="Method" /> is legal for use.
|
||||
/// </summary>
|
||||
/// <returns><c>null</c> or the appropriate error message.</returns>
|
||||
private string ValidateMethodParameter()
|
||||
{
|
||||
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)
|
||||
&& m.IsPublic && m.IsStatic);
|
||||
if (methodInfo == null)
|
||||
{
|
||||
return string.Format(CultureInfo.CurrentCulture,
|
||||
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);
|
||||
}
|
||||
|
||||
ParameterInfo[] parameterInfos = methodInfo.GetParameters();
|
||||
|
||||
// Must declare at least one input parameter for the value and it cannot be ByRef
|
||||
if (parameterInfos.Length == 0 || parameterInfos[0].ParameterType.IsByRef)
|
||||
{
|
||||
return string.Format(CultureInfo.CurrentCulture,
|
||||
SR.CustomValidationAttribute_Method_Signature, _method, _validatorType.Name);
|
||||
}
|
||||
|
||||
// We accept 2 forms:
|
||||
// 1-parameter form is ValidationResult Method(object value)
|
||||
// 2-parameter form is ValidationResult Method(object value, ValidationContext context),
|
||||
_isSingleArgumentMethod = (parameterInfos.Length == 1);
|
||||
|
||||
if (!_isSingleArgumentMethod)
|
||||
{
|
||||
if ((parameterInfos.Length != 2) || (parameterInfos[1].ParameterType != typeof(ValidationContext)))
|
||||
{
|
||||
return string.Format(CultureInfo.CurrentCulture,
|
||||
SR.CustomValidationAttribute_Method_Signature, _method,
|
||||
_validatorType.Name);
|
||||
}
|
||||
}
|
||||
|
||||
_methodInfo = methodInfo;
|
||||
_firstParameterType = parameterInfos[0].ParameterType;
|
||||
return null;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Throws InvalidOperationException if the attribute is not valid.
|
||||
/// </summary>
|
||||
private void ThrowIfAttributeNotWellFormed()
|
||||
{
|
||||
string errorMessage = _malformedErrorMessage.Value;
|
||||
if (errorMessage != null)
|
||||
{
|
||||
throw new InvalidOperationException(errorMessage);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Attempts to convert the given value to the type needed to invoke the method for the current
|
||||
/// CustomValidationAttribute.
|
||||
/// </summary>
|
||||
/// <param name="value">The value to check/convert.</param>
|
||||
/// <param name="convertedValue">If successful, the converted (or copied) value.</param>
|
||||
/// <returns><c>true</c> if type value was already correct or was successfully converted.</returns>
|
||||
private bool TryConvertValue(object value, out object convertedValue)
|
||||
{
|
||||
convertedValue = null;
|
||||
var expectedValueType = _firstParameterType;
|
||||
|
||||
// Null is permitted for reference types or for Nullable<>'s only
|
||||
if (value == null)
|
||||
{
|
||||
if (expectedValueType.GetTypeInfo().IsValueType
|
||||
&& (!expectedValueType.GetTypeInfo().IsGenericType
|
||||
|| expectedValueType.GetGenericTypeDefinition() != typeof(Nullable<>)))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
return true; // convertedValue already null, which is correct for this case
|
||||
}
|
||||
|
||||
// If the type is already legally assignable, we're good
|
||||
if (expectedValueType.GetTypeInfo().IsAssignableFrom(value.GetType().GetTypeInfo()))
|
||||
{
|
||||
convertedValue = value;
|
||||
return true;
|
||||
}
|
||||
|
||||
// Value is not the right type -- attempt a convert.
|
||||
// Any expected exception returns a false
|
||||
try
|
||||
{
|
||||
convertedValue = Convert.ChangeType(value, expectedValueType, CultureInfo.CurrentCulture);
|
||||
return true;
|
||||
}
|
||||
catch (FormatException)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
catch (InvalidCastException)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
catch (NotSupportedException)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,97 @@
|
||||
// Licensed to the .NET Foundation under one or more agreements.
|
||||
// The .NET Foundation licenses this file to you under the MIT license.
|
||||
// See the LICENSE file in the project root for more information.
|
||||
|
||||
namespace System.ComponentModel.DataAnnotations
|
||||
{
|
||||
/// <summary>
|
||||
/// Enumeration of logical data types that may appear in <see cref="DataTypeAttribute" />
|
||||
/// </summary>
|
||||
public enum DataType
|
||||
{
|
||||
/// <summary>
|
||||
/// Custom data type, not one of the static data types we know
|
||||
/// </summary>
|
||||
Custom = 0,
|
||||
|
||||
/// <summary>
|
||||
/// DateTime data type
|
||||
/// </summary>
|
||||
DateTime = 1,
|
||||
|
||||
/// <summary>
|
||||
/// Date data type
|
||||
/// </summary>
|
||||
Date = 2,
|
||||
|
||||
/// <summary>
|
||||
/// Time data type
|
||||
/// </summary>
|
||||
Time = 3,
|
||||
|
||||
/// <summary>
|
||||
/// Duration data type
|
||||
/// </summary>
|
||||
Duration = 4,
|
||||
|
||||
/// <summary>
|
||||
/// Phone number data type
|
||||
/// </summary>
|
||||
PhoneNumber = 5,
|
||||
|
||||
/// <summary>
|
||||
/// Currency data type
|
||||
/// </summary>
|
||||
Currency = 6,
|
||||
|
||||
/// <summary>
|
||||
/// Plain text data type
|
||||
/// </summary>
|
||||
Text = 7,
|
||||
|
||||
/// <summary>
|
||||
/// Html data type
|
||||
/// </summary>
|
||||
Html = 8,
|
||||
|
||||
/// <summary>
|
||||
/// Multiline text data type
|
||||
/// </summary>
|
||||
MultilineText = 9,
|
||||
|
||||
/// <summary>
|
||||
/// Email address data type
|
||||
/// </summary>
|
||||
EmailAddress = 10,
|
||||
|
||||
/// <summary>
|
||||
/// Password data type -- do not echo in UI
|
||||
/// </summary>
|
||||
Password = 11,
|
||||
|
||||
/// <summary>
|
||||
/// URL data type
|
||||
/// </summary>
|
||||
Url = 12,
|
||||
|
||||
/// <summary>
|
||||
/// URL to an Image -- to be displayed as an image instead of text
|
||||
/// </summary>
|
||||
ImageUrl = 13,
|
||||
|
||||
/// <summary>
|
||||
/// Credit card data type
|
||||
/// </summary>
|
||||
CreditCard = 14,
|
||||
|
||||
/// <summary>
|
||||
/// Postal code data type
|
||||
/// </summary>
|
||||
PostalCode = 15,
|
||||
|
||||
/// <summary>
|
||||
/// File upload data type
|
||||
/// </summary>
|
||||
Upload = 16
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,125 @@
|
||||
// Licensed to the .NET Foundation under one or more agreements.
|
||||
// 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.Globalization;
|
||||
|
||||
namespace System.ComponentModel.DataAnnotations
|
||||
{
|
||||
/// <summary>
|
||||
/// Allows for clarification of the <see cref="DataType" /> represented by a given
|
||||
/// property (such as <see cref="System.ComponentModel.DataAnnotations.DataType.PhoneNumber" />
|
||||
/// or <see cref="System.ComponentModel.DataAnnotations.DataType.Url" />)
|
||||
/// </summary>
|
||||
[AttributeUsage(
|
||||
AttributeTargets.Property | AttributeTargets.Field | AttributeTargets.Method | AttributeTargets.Parameter,
|
||||
AllowMultiple = false)]
|
||||
public class DataTypeAttribute : ValidationAttribute
|
||||
{
|
||||
private static readonly string[] _dataTypeStrings = Enum.GetNames(typeof(DataType));
|
||||
|
||||
/// <summary>
|
||||
/// Constructor that accepts a data type enumeration
|
||||
/// </summary>
|
||||
/// <param name="dataType">The <see cref="DataType" /> enum value indicating the type to apply.</param>
|
||||
public DataTypeAttribute(DataType dataType)
|
||||
{
|
||||
DataType = dataType;
|
||||
|
||||
// Set some DisplayFormat for a few specific data types
|
||||
switch (dataType)
|
||||
{
|
||||
case DataType.Date:
|
||||
DisplayFormat = new DisplayFormatAttribute();
|
||||
DisplayFormat.DataFormatString = "{0:d}";
|
||||
DisplayFormat.ApplyFormatInEditMode = true;
|
||||
break;
|
||||
case DataType.Time:
|
||||
DisplayFormat = new DisplayFormatAttribute();
|
||||
DisplayFormat.DataFormatString = "{0:t}";
|
||||
DisplayFormat.ApplyFormatInEditMode = true;
|
||||
break;
|
||||
case DataType.Currency:
|
||||
DisplayFormat = new DisplayFormatAttribute();
|
||||
DisplayFormat.DataFormatString = "{0:C}";
|
||||
|
||||
// Don't set ApplyFormatInEditMode for currencies because the currency
|
||||
// symbol can't be parsed
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Constructor that accepts the string name of a custom data type
|
||||
/// </summary>
|
||||
/// <param name="customDataType">The string name of the custom data type.</param>
|
||||
public DataTypeAttribute(string customDataType)
|
||||
: this(DataType.Custom)
|
||||
{
|
||||
CustomDataType = customDataType;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the DataType. If it equals DataType.Custom, <see cref="CustomDataType" /> should also be retrieved.
|
||||
/// </summary>
|
||||
public DataType DataType { get; private set; }
|
||||
|
||||
/// <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; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the default display format that gets used along with this DataType.
|
||||
/// </summary>
|
||||
public DisplayFormatAttribute DisplayFormat { get; protected set; }
|
||||
|
||||
/// <summary>
|
||||
/// Return the name of the data type, either using the <see cref="DataType" /> enum or <see cref="CustomDataType" />
|
||||
/// string
|
||||
/// </summary>
|
||||
/// <returns>The name of the data type enum</returns>
|
||||
/// <exception cref="InvalidOperationException"> is thrown if the current attribute is ill-formed.</exception>
|
||||
public virtual string GetDataTypeName()
|
||||
{
|
||||
EnsureValidDataType();
|
||||
|
||||
if (DataType == DataType.Custom)
|
||||
{
|
||||
// If it's a custom type string, use it as the template name
|
||||
return CustomDataType;
|
||||
}
|
||||
// If it's an enum, turn it into a string
|
||||
// Use the cached array with enum string values instead of ToString() as the latter is too slow
|
||||
return _dataTypeStrings[(int)DataType];
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Override of <see cref="ValidationAttribute.IsValid(object)" />
|
||||
/// </summary>
|
||||
/// <remarks>This override always returns <c>true</c>. Subclasses should override this to provide the correct result.</remarks>
|
||||
/// <param name="value">The value to validate</param>
|
||||
/// <returns>Unconditionally returns <c>true</c></returns>
|
||||
/// <exception cref="InvalidOperationException"> is thrown if the current attribute is ill-formed.</exception>
|
||||
public override bool IsValid(object value)
|
||||
{
|
||||
EnsureValidDataType();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Throws an exception if this attribute is not correctly formed
|
||||
/// </summary>
|
||||
/// <exception cref="InvalidOperationException"> is thrown if the current attribute is ill-formed.</exception>
|
||||
private void EnsureValidDataType()
|
||||
{
|
||||
if (DataType == DataType.Custom && string.IsNullOrWhiteSpace(CustomDataType))
|
||||
{
|
||||
throw new InvalidOperationException(string.Format(CultureInfo.CurrentCulture,
|
||||
SR.DataTypeAttribute_EmptyDataTypeString));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,494 @@
|
||||
// Licensed to the .NET Foundation under one or more agreements.
|
||||
// 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.Globalization;
|
||||
|
||||
namespace System.ComponentModel.DataAnnotations
|
||||
{
|
||||
/// <summary>
|
||||
/// DisplayAttribute is a general-purpose attribute to specify user-visible globalizable strings for types and members.
|
||||
/// The string properties of this class can be used either as literals or as resource identifiers into a specified
|
||||
/// <see cref="ResourceType" />
|
||||
/// </summary>
|
||||
[AttributeUsage(
|
||||
AttributeTargets.Property | AttributeTargets.Field | AttributeTargets.Parameter | AttributeTargets.Method,
|
||||
AllowMultiple = false)]
|
||||
public sealed class DisplayAttribute : Attribute
|
||||
{
|
||||
#region Member Fields
|
||||
|
||||
private readonly LocalizableString _description = new LocalizableString("Description");
|
||||
private readonly LocalizableString _groupName = new LocalizableString("GroupName");
|
||||
private readonly LocalizableString _name = new LocalizableString("Name");
|
||||
private readonly LocalizableString _prompt = new LocalizableString("Prompt");
|
||||
private readonly LocalizableString _shortName = new LocalizableString("ShortName");
|
||||
private bool? _autoGenerateField;
|
||||
private bool? _autoGenerateFilter;
|
||||
private int? _order;
|
||||
private Type _resourceType;
|
||||
|
||||
#endregion
|
||||
|
||||
#region All Constructors
|
||||
|
||||
#endregion
|
||||
|
||||
#region Properties
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the ShortName attribute property, which may be a resource key string.
|
||||
/// <para>
|
||||
/// Consumers must use the <see cref="GetShortName" /> method to retrieve the UI display string.
|
||||
/// </para>
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// The property contains either the literal, non-localized string or the resource key
|
||||
/// to be used in conjunction with <see cref="ResourceType" /> to configure a localized
|
||||
/// short name for display.
|
||||
/// <para>
|
||||
/// The <see cref="GetShortName" /> method will return either the literal, non-localized
|
||||
/// string or the localized string when <see cref="ResourceType" /> has been specified.
|
||||
/// </para>
|
||||
/// </remarks>
|
||||
/// <value>
|
||||
/// The short name is generally used as the grid column label for a UI element bound to the member
|
||||
/// bearing this attribute. A <c>null</c> or empty string is legal, and consumers must allow for that.
|
||||
/// </value>
|
||||
public string ShortName
|
||||
{
|
||||
get { return _shortName.Value; }
|
||||
set
|
||||
{
|
||||
if (_shortName.Value != value)
|
||||
{
|
||||
_shortName.Value = value;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the Name attribute property, which may be a resource key string.
|
||||
/// <para>
|
||||
/// Consumers must use the <see cref="GetName" /> method to retrieve the UI display string.
|
||||
/// </para>
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// The property contains either the literal, non-localized string or the resource key
|
||||
/// to be used in conjunction with <see cref="ResourceType" /> to configure a localized
|
||||
/// name for display.
|
||||
/// <para>
|
||||
/// The <see cref="GetName" /> method will return either the literal, non-localized
|
||||
/// string or the localized string when <see cref="ResourceType" /> has been specified.
|
||||
/// </para>
|
||||
/// </remarks>
|
||||
/// <value>
|
||||
/// The name is generally used as the field label for a UI element bound to the member
|
||||
/// bearing this attribute. A <c>null</c> or empty string is legal, and consumers must allow for that.
|
||||
/// </value>
|
||||
public string Name
|
||||
{
|
||||
get { return _name.Value; }
|
||||
set
|
||||
{
|
||||
if (_name.Value != value)
|
||||
{
|
||||
_name.Value = value;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the Description attribute property, which may be a resource key string.
|
||||
/// <para>
|
||||
/// Consumers must use the <see cref="GetDescription" /> method to retrieve the UI display string.
|
||||
/// </para>
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// The property contains either the literal, non-localized string or the resource key
|
||||
/// to be used in conjunction with <see cref="ResourceType" /> to configure a localized
|
||||
/// description for display.
|
||||
/// <para>
|
||||
/// The <see cref="GetDescription" /> method will return either the literal, non-localized
|
||||
/// string or the localized string when <see cref="ResourceType" /> has been specified.
|
||||
/// </para>
|
||||
/// </remarks>
|
||||
/// <value>
|
||||
/// Description is generally used as a tool tip or description a UI element bound to the member
|
||||
/// bearing this attribute. A <c>null</c> or empty string is legal, and consumers must allow for that.
|
||||
/// </value>
|
||||
public string Description
|
||||
{
|
||||
get { return _description.Value; }
|
||||
set
|
||||
{
|
||||
if (_description.Value != value)
|
||||
{
|
||||
_description.Value = value;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the Prompt attribute property, which may be a resource key string.
|
||||
/// <para>
|
||||
/// Consumers must use the <see cref="GetPrompt" /> method to retrieve the UI display string.
|
||||
/// </para>
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// The property contains either the literal, non-localized string or the resource key
|
||||
/// to be used in conjunction with <see cref="ResourceType" /> to configure a localized
|
||||
/// prompt for display.
|
||||
/// <para>
|
||||
/// The <see cref="GetPrompt" /> method will return either the literal, non-localized
|
||||
/// string or the localized string when <see cref="ResourceType" /> has been specified.
|
||||
/// </para>
|
||||
/// </remarks>
|
||||
/// <value>
|
||||
/// A prompt is generally used as a prompt or watermark for a UI element bound to the member
|
||||
/// bearing this attribute. A <c>null</c> or empty string is legal, and consumers must allow for that.
|
||||
/// </value>
|
||||
public string Prompt
|
||||
{
|
||||
get { return _prompt.Value; }
|
||||
set
|
||||
{
|
||||
if (_prompt.Value != value)
|
||||
{
|
||||
_prompt.Value = value;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the GroupName attribute property, which may be a resource key string.
|
||||
/// <para>
|
||||
/// Consumers must use the <see cref="GetGroupName" /> method to retrieve the UI display string.
|
||||
/// </para>
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// The property contains either the literal, non-localized string or the resource key
|
||||
/// to be used in conjunction with <see cref="ResourceType" /> to configure a localized
|
||||
/// group name for display.
|
||||
/// <para>
|
||||
/// The <see cref="GetGroupName" /> method will return either the literal, non-localized
|
||||
/// string or the localized string when <see cref="ResourceType" /> has been specified.
|
||||
/// </para>
|
||||
/// </remarks>
|
||||
/// <value>
|
||||
/// A group name is used for grouping fields into the UI. A <c>null</c> or empty string is legal,
|
||||
/// and consumers must allow for that.
|
||||
/// </value>
|
||||
public string GroupName
|
||||
{
|
||||
get { return _groupName.Value; }
|
||||
set
|
||||
{
|
||||
if (_groupName.Value != value)
|
||||
{
|
||||
_groupName.Value = value;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the <see cref="System.Type" /> that contains the resources for <see cref="ShortName" />,
|
||||
/// <see cref="Name" />, <see cref="Description" />, <see cref="Prompt" />, and <see cref="GroupName" />.
|
||||
/// Using <see cref="ResourceType" /> along with these Key properties, allows the <see cref="GetShortName" />,
|
||||
/// <see cref="GetName" />, <see cref="GetDescription" />, <see cref="GetPrompt" />, and <see cref="GetGroupName" />
|
||||
/// methods to return localized values.
|
||||
/// </summary>
|
||||
public Type ResourceType
|
||||
{
|
||||
get { return _resourceType; }
|
||||
set
|
||||
{
|
||||
if (_resourceType != value)
|
||||
{
|
||||
_resourceType = value;
|
||||
|
||||
_shortName.ResourceType = value;
|
||||
_name.ResourceType = value;
|
||||
_description.ResourceType = value;
|
||||
_prompt.ResourceType = value;
|
||||
_groupName.ResourceType = value;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets whether UI should be generated automatically to display this field. If this property is not
|
||||
/// set then the presentation layer will automatically determine whether UI should be generated. Setting this
|
||||
/// property allows an override of the default behavior of the presentation layer.
|
||||
/// <para>
|
||||
/// Consumers must use the <see cref="GetAutoGenerateField" /> method to retrieve the value, as this property
|
||||
/// getter will throw
|
||||
/// an exception if the value has not been set.
|
||||
/// </para>
|
||||
/// </summary>
|
||||
/// <exception cref="System.InvalidOperationException">
|
||||
/// If the getter of this property is invoked when the value has not been explicitly set using the setter.
|
||||
/// </exception>
|
||||
public bool AutoGenerateField
|
||||
{
|
||||
get
|
||||
{
|
||||
if (!_autoGenerateField.HasValue)
|
||||
{
|
||||
throw new InvalidOperationException(string.Format(CultureInfo.CurrentCulture,
|
||||
SR.DisplayAttribute_PropertyNotSet, "AutoGenerateField",
|
||||
"GetAutoGenerateField"));
|
||||
}
|
||||
|
||||
return _autoGenerateField.Value;
|
||||
}
|
||||
set { _autoGenerateField = value; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets whether UI should be generated automatically to display filtering for this field. If this property is
|
||||
/// not
|
||||
/// set then the presentation layer will automatically determine whether filtering UI should be generated. Setting this
|
||||
/// property allows an override of the default behavior of the presentation layer.
|
||||
/// <para>
|
||||
/// Consumers must use the <see cref="GetAutoGenerateFilter" /> method to retrieve the value, as this property
|
||||
/// getter will throw
|
||||
/// an exception if the value has not been set.
|
||||
/// </para>
|
||||
/// </summary>
|
||||
/// <exception cref="System.InvalidOperationException">
|
||||
/// If the getter of this property is invoked when the value has not been explicitly set using the setter.
|
||||
/// </exception>
|
||||
public bool AutoGenerateFilter
|
||||
{
|
||||
get
|
||||
{
|
||||
if (!_autoGenerateFilter.HasValue)
|
||||
{
|
||||
throw new InvalidOperationException(string.Format(CultureInfo.CurrentCulture,
|
||||
SR.DisplayAttribute_PropertyNotSet, "AutoGenerateFilter",
|
||||
"GetAutoGenerateFilter"));
|
||||
}
|
||||
|
||||
return _autoGenerateFilter.Value;
|
||||
}
|
||||
set { _autoGenerateFilter = value; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the order in which this field should be displayed. If this property is not set then
|
||||
/// the presentation layer will automatically determine the order. Setting this property explicitly
|
||||
/// allows an override of the default behavior of the presentation layer.
|
||||
/// <para>
|
||||
/// Consumers must use the <see cref="GetOrder" /> method to retrieve the value, as this property getter will throw
|
||||
/// an exception if the value has not been set.
|
||||
/// </para>
|
||||
/// </summary>
|
||||
/// <exception cref="System.InvalidOperationException">
|
||||
/// If the getter of this property is invoked when the value has not been explicitly set using the setter.
|
||||
/// </exception>
|
||||
public int Order
|
||||
{
|
||||
get
|
||||
{
|
||||
if (!_order.HasValue)
|
||||
{
|
||||
throw new InvalidOperationException(string.Format(CultureInfo.CurrentCulture,
|
||||
SR.DisplayAttribute_PropertyNotSet, "Order", "GetOrder"));
|
||||
}
|
||||
|
||||
return _order.Value;
|
||||
}
|
||||
set { _order = value; }
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Methods
|
||||
|
||||
/// <summary>
|
||||
/// Gets the UI display string for ShortName.
|
||||
/// <para>
|
||||
/// This can be either a literal, non-localized string provided to <see cref="ShortName" /> or the
|
||||
/// localized string found when <see cref="ResourceType" /> has been specified and <see cref="ShortName" />
|
||||
/// represents a resource key within that resource type.
|
||||
/// </para>
|
||||
/// </summary>
|
||||
/// <returns>
|
||||
/// When <see cref="ResourceType" /> has not been specified, the value of
|
||||
/// <see cref="ShortName" /> will be returned.
|
||||
/// <para>
|
||||
/// When <see cref="ResourceType" /> has been specified and <see cref="ShortName" />
|
||||
/// represents a resource key within that resource type, then the localized value will be returned.
|
||||
/// </para>
|
||||
/// <para>
|
||||
/// If <see cref="ShortName" /> is <c>null</c>, the value from <see cref="GetName" /> will be returned.
|
||||
/// </para>
|
||||
/// </returns>
|
||||
/// <exception cref="System.InvalidOperationException">
|
||||
/// After setting both the <see cref="ResourceType" /> property and the <see cref="ShortName" /> property,
|
||||
/// 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();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the UI display string for Name.
|
||||
/// <para>
|
||||
/// This can be either a literal, non-localized string provided to <see cref="Name" /> or the
|
||||
/// localized string found when <see cref="ResourceType" /> has been specified and <see cref="Name" />
|
||||
/// represents a resource key within that resource type.
|
||||
/// </para>
|
||||
/// </summary>
|
||||
/// <returns>
|
||||
/// When <see cref="ResourceType" /> has not been specified, the value of
|
||||
/// <see cref="Name" /> will be returned.
|
||||
/// <para>
|
||||
/// When <see cref="ResourceType" /> has been specified and <see cref="Name" />
|
||||
/// represents a resource key within that resource type, then the localized value will be returned.
|
||||
/// </para>
|
||||
/// <para>
|
||||
/// Can return <c>null</c> and will not fall back onto other values, as it's more likely for the
|
||||
/// consumer to want to fall back onto the property name.
|
||||
/// </para>
|
||||
/// </returns>
|
||||
/// <exception cref="System.InvalidOperationException">
|
||||
/// After setting both the <see cref="ResourceType" /> property and the <see cref="Name" /> property,
|
||||
/// 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();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the UI display string for Description.
|
||||
/// <para>
|
||||
/// This can be either a literal, non-localized string provided to <see cref="Description" /> or the
|
||||
/// localized string found when <see cref="ResourceType" /> has been specified and <see cref="Description" />
|
||||
/// represents a resource key within that resource type.
|
||||
/// </para>
|
||||
/// </summary>
|
||||
/// <returns>
|
||||
/// When <see cref="ResourceType" /> has not been specified, the value of
|
||||
/// <see cref="Description" /> will be returned.
|
||||
/// <para>
|
||||
/// When <see cref="ResourceType" /> has been specified and <see cref="Description" />
|
||||
/// represents a resource key within that resource type, then the localized value will be returned.
|
||||
/// </para>
|
||||
/// </returns>
|
||||
/// <exception cref="System.InvalidOperationException">
|
||||
/// After setting both the <see cref="ResourceType" /> property and the <see cref="Description" /> property,
|
||||
/// 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();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the UI display string for Prompt.
|
||||
/// <para>
|
||||
/// This can be either a literal, non-localized string provided to <see cref="Prompt" /> or the
|
||||
/// localized string found when <see cref="ResourceType" /> has been specified and <see cref="Prompt" />
|
||||
/// represents a resource key within that resource type.
|
||||
/// </para>
|
||||
/// </summary>
|
||||
/// <returns>
|
||||
/// When <see cref="ResourceType" /> has not been specified, the value of
|
||||
/// <see cref="Prompt" /> will be returned.
|
||||
/// <para>
|
||||
/// When <see cref="ResourceType" /> has been specified and <see cref="Prompt" />
|
||||
/// represents a resource key within that resource type, then the localized value will be returned.
|
||||
/// </para>
|
||||
/// </returns>
|
||||
/// <exception cref="System.InvalidOperationException">
|
||||
/// After setting both the <see cref="ResourceType" /> property and the <see cref="Prompt" /> property,
|
||||
/// 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();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the UI display string for GroupName.
|
||||
/// <para>
|
||||
/// This can be either a literal, non-localized string provided to <see cref="GroupName" /> or the
|
||||
/// localized string found when <see cref="ResourceType" /> has been specified and <see cref="GroupName" />
|
||||
/// represents a resource key within that resource type.
|
||||
/// </para>
|
||||
/// </summary>
|
||||
/// <returns>
|
||||
/// When <see cref="ResourceType" /> has not been specified, the value of
|
||||
/// <see cref="GroupName" /> will be returned.
|
||||
/// <para>
|
||||
/// When <see cref="ResourceType" /> has been specified and <see cref="GroupName" />
|
||||
/// represents a resource key within that resource type, then the localized value will be returned.
|
||||
/// </para>
|
||||
/// </returns>
|
||||
/// <exception cref="System.InvalidOperationException">
|
||||
/// After setting both the <see cref="ResourceType" /> property and the <see cref="GroupName" /> property,
|
||||
/// 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();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the value of <see cref="AutoGenerateField" /> if it has been set, or <c>null</c>.
|
||||
/// </summary>
|
||||
/// <returns>
|
||||
/// When <see cref="AutoGenerateField" /> has been set returns the value of that property.
|
||||
/// <para>
|
||||
/// When <see cref="AutoGenerateField" /> has not been set returns <c>null</c>.
|
||||
/// </para>
|
||||
/// </returns>
|
||||
public bool? GetAutoGenerateField()
|
||||
{
|
||||
return _autoGenerateField;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the value of <see cref="AutoGenerateFilter" /> if it has been set, or <c>null</c>.
|
||||
/// </summary>
|
||||
/// <returns>
|
||||
/// When <see cref="AutoGenerateFilter" /> has been set returns the value of that property.
|
||||
/// <para>
|
||||
/// When <see cref="AutoGenerateFilter" /> has not been set returns <c>null</c>.
|
||||
/// </para>
|
||||
/// </returns>
|
||||
public bool? GetAutoGenerateFilter()
|
||||
{
|
||||
return _autoGenerateFilter;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the value of <see cref="Order" /> if it has been set, or <c>null</c>.
|
||||
/// </summary>
|
||||
/// <returns>
|
||||
/// When <see cref="Order" /> has been set returns the value of that property.
|
||||
/// <para>
|
||||
/// When <see cref="Order" /> has not been set returns <c>null</c>.
|
||||
/// </para>
|
||||
/// </returns>
|
||||
/// <remarks>
|
||||
/// When an order is not specified, presentation layers should consider using the value
|
||||
/// 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;
|
||||
}
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,37 @@
|
||||
// Licensed to the .NET Foundation under one or more agreements.
|
||||
// The .NET Foundation licenses this file to you under the MIT license.
|
||||
// See the LICENSE file in the project root for more information.
|
||||
|
||||
namespace System.ComponentModel.DataAnnotations
|
||||
{
|
||||
/// <summary>
|
||||
/// Sets the display column, the sort column, and the sort order for when a table is used as a parent table in FK
|
||||
/// relationships.
|
||||
/// </summary>
|
||||
[AttributeUsage(AttributeTargets.Class, Inherited = true, AllowMultiple = false)]
|
||||
public class DisplayColumnAttribute : Attribute
|
||||
{
|
||||
public DisplayColumnAttribute(string displayColumn)
|
||||
: this(displayColumn, null)
|
||||
{
|
||||
}
|
||||
|
||||
public DisplayColumnAttribute(string displayColumn, string sortColumn)
|
||||
: this(displayColumn, sortColumn, false)
|
||||
{
|
||||
}
|
||||
|
||||
public DisplayColumnAttribute(string displayColumn, string sortColumn, bool sortDescending)
|
||||
{
|
||||
DisplayColumn = displayColumn;
|
||||
SortColumn = sortColumn;
|
||||
SortDescending = sortDescending;
|
||||
}
|
||||
|
||||
public string DisplayColumn { get; private set; }
|
||||
|
||||
public string SortColumn { get; private set; }
|
||||
|
||||
public bool SortDescending { get; private set; }
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,49 @@
|
||||
// Licensed to the .NET Foundation under one or more agreements.
|
||||
// The .NET Foundation licenses this file to you under the MIT license.
|
||||
// See the LICENSE file in the project root for more information.
|
||||
|
||||
namespace System.ComponentModel.DataAnnotations
|
||||
{
|
||||
/// <summary>
|
||||
/// Allows overriding various display-related options for a given field. The options have the same meaning as in
|
||||
/// BoundField.
|
||||
/// </summary>
|
||||
[AttributeUsage(AttributeTargets.Property | AttributeTargets.Field, AllowMultiple = false)]
|
||||
public class DisplayFormatAttribute : Attribute
|
||||
{
|
||||
/// <summary>
|
||||
/// Default constructor
|
||||
/// </summary>
|
||||
public DisplayFormatAttribute()
|
||||
{
|
||||
ConvertEmptyStringToNull = true; // default to true to match behavior in related components
|
||||
|
||||
HtmlEncode = true; // default to true to match behavior in related components
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the format string
|
||||
/// </summary>
|
||||
public string DataFormatString { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the string to display when the value is null
|
||||
/// </summary>
|
||||
public string NullDisplayText { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets a value indicating whether empty strings should be set to null
|
||||
/// </summary>
|
||||
public bool ConvertEmptyStringToNull { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets a value indicating whether the format string should be used in edit mode
|
||||
/// </summary>
|
||||
public bool ApplyFormatInEditMode { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets a value indicating whether the field should be html encoded
|
||||
/// </summary>
|
||||
public bool HtmlEncode { get; set; }
|
||||
}
|
||||
}
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user