├── .gitignore
├── LICENSE
├── Microsoft-License.txt
├── Microsoft-Patents.txt
├── Portable.DataAnnotations.Net40
├── Portable.DataAnnotations.Net40.csproj
├── Properties
│ └── AssemblyInfo.cs
├── Resources
│ ├── DataAnnotationsResources.Designer.cs
│ └── DataAnnotationsResources.resx
└── TypeForwards.cs
├── Portable.DataAnnotations.Net40Portable
├── Portable.DataAnnotations.Net40Portable.csproj
├── Properties
│ └── AssemblyInfo.cs
└── Resources
│ ├── DataAnnotationsResources.Designer.cs
│ └── DataAnnotationsResources.resx
├── Portable.DataAnnotations.Net45
├── Portable.DataAnnotations.Net45.csproj
├── Properties
│ └── AssemblyInfo.cs
└── TypeForwards.cs
├── Portable.DataAnnotations.Net45Portable
├── DataType.cs
├── GlobalSuppressions.cs
├── IValidatableObject.cs
├── LocalizableString.cs
├── Portable.DataAnnotations.Net45Portable.csproj
├── Properties
│ └── AssemblyInfo.cs
├── Resources
│ ├── DataAnnotationsResources.Designer.cs
│ └── DataAnnotationsResources.resx
├── ValidationAttributeStore.cs
├── ValidationAttributes
│ ├── AssociationAttribute.cs
│ ├── BindableTypeAttribute.cs
│ ├── ConcurrencyCheckAttribute.cs
│ ├── CreditCardAttribute.cs
│ ├── CustomValidationAttribute.cs
│ ├── DataTypeAttribute.cs
│ ├── DisplayAttribute.cs
│ ├── DisplayColumnAttribute.cs
│ ├── DisplayFormatAttribute.cs
│ ├── EditableAttribute.cs
│ ├── EmailAddressAttribute.cs
│ ├── EnumDataTypeAttribute.cs
│ ├── FilterUIHintAttribute.cs
│ ├── KeyAttribute.cs
│ ├── MaxLengthAttribute.cs
│ ├── MetadataTypeAttribute.cs
│ ├── MinLengthAttribute.cs
│ ├── PhoneAttribute.cs
│ ├── RangeAttribute.cs
│ ├── RegularExpressionAttribute.cs
│ ├── RequiredAttribute.cs
│ ├── Schema
│ │ ├── ColumnAttribute.cs
│ │ ├── ComplexTypeAttribute.cs
│ │ ├── DatabaseGeneratedAttribute.cs
│ │ ├── DatabaseGeneratedOption.cs
│ │ ├── ForeignKeyAttribute.cs
│ │ ├── InversePropertyAttribute.cs
│ │ ├── NotMappedAttribute.cs
│ │ └── TableAttribute.cs
│ ├── StringLengthAttribute.cs
│ ├── TimestampAttribute.cs
│ ├── UIHintAttribute.cs
│ ├── UrlAttribute.cs
│ └── ValidationAttribute.cs
├── ValidationContext.cs
├── ValidationException.cs
├── ValidationResult.cs
└── Validator.cs
├── Portable.DataAnnotations.WindowsRuntime
├── Portable.DataAnnotations.WindowsRuntime.csproj
├── Properties
│ └── AssemblyInfo.cs
├── Resources
│ ├── DataAnnotationsResources.Designer.cs
│ └── DataAnnotationsResources.resx
├── TypeForwards.cs
└── ValidationAttributes
│ ├── CreditCardAttribute.cs
│ ├── EmailAddressAttribute.cs
│ ├── MaxLengthAttribute.cs
│ ├── MinLengthAttribute.cs
│ ├── PhoneAttribute.cs
│ └── UrlAttribute.cs
├── Portable.DataAnnotations.Xamarin
├── Portable.DataAnnotations.Xamarin.csproj
├── Properties
│ └── AssemblyInfo.cs
└── Resources
│ ├── DataAnnotationsResources.Designer.cs
│ └── DataAnnotationsResources.resx
├── Portable.DataAnnotations.nuspec
├── Portable.DataAnnotations.sln
├── README.md
└── Rybird-32.png
/.gitignore:
--------------------------------------------------------------------------------
1 | ################################################################################
2 | # This .gitignore file was automatically created by Microsoft(R) Visual Studio.
3 | ################################################################################
4 |
5 | /Portable.DataAnnotations.Net40/obj
6 | /Portable.DataAnnotations.Net40/bin
7 | /Portable.DataAnnotations.Net40/bin
8 | /Portable.DataAnnotations.Net40/bin
9 | /Portable.DataAnnotations.Net40Portable/bin/Release
10 | /Portable.DataAnnotations.Net40Portable/obj
11 | /Portable.DataAnnotations.Net45/bin/Release
12 | /Portable.DataAnnotations.Net45/obj
13 | /Portable.DataAnnotations.Net45Portable/bin
14 | /Portable.DataAnnotations.Net45Portable/obj
15 | /Portable.DataAnnotations.WindowsRuntime/obj
16 | /Portable.DataAnnotations.WindowsRuntime/bin
17 | /Portable.DataAnnotations.Xamarin/obj
18 | /Portable.DataAnnotations.Xamarin/bin
19 | NuGet.Config
20 | NuGet.exe
21 | NuGet.targets
22 | /Portable.DataAnnotations.v12.suo
23 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | The MIT License (MIT)
2 |
3 | Copyright (c) 2015 ryanhorath
4 |
5 | Permission is hereby granted, free of charge, to any person obtaining a copy
6 | of this software and associated documentation files (the "Software"), to deal
7 | in the Software without restriction, including without limitation the rights
8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 | copies of the Software, and to permit persons to whom the Software is
10 | furnished to do so, subject to the following conditions:
11 |
12 | The above copyright notice and this permission notice shall be included in all
13 | copies or substantial portions of the Software.
14 |
15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21 | SOFTWARE.
22 |
23 |
--------------------------------------------------------------------------------
/Microsoft-License.txt:
--------------------------------------------------------------------------------
1 | The MIT License (MIT)
2 |
3 | Copyright (c) Microsoft Corporation
4 |
5 | Permission is hereby granted, free of charge, to any person obtaining a copy
6 | of this software and associated documentation files (the "Software"), to deal
7 | in the Software without restriction, including without limitation the rights
8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 | copies of the Software, and to permit persons to whom the Software is
10 | furnished to do so, subject to the following conditions:
11 |
12 | The above copyright notice and this permission notice shall be included in all
13 | copies or substantial portions of the Software.
14 |
15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21 | SOFTWARE.
--------------------------------------------------------------------------------
/Portable.DataAnnotations.Net40/Portable.DataAnnotations.Net40.csproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | Debug
6 | AnyCPU
7 | {F061DE0B-67ED-4F7B-BB3F-01A45FCAA266}
8 | Library
9 | Properties
10 | System.ComponentModel.DataAnnotations
11 | Portable.DataAnnotations
12 | v4.0
13 | 512
14 |
15 |
16 |
17 | true
18 | full
19 | false
20 | bin\Debug\
21 | DEBUG;TRACE
22 | prompt
23 | 4
24 |
25 |
26 | pdbonly
27 | true
28 | bin\Release\
29 | TRACE
30 | prompt
31 | 4
32 |
33 |
34 |
35 |
36 |
37 |
38 |
39 |
40 |
41 |
42 |
43 |
44 |
45 | ValidationAttributes\BindableTypeAttribute.cs
46 |
47 |
48 | ValidationAttributes\Schema\ColumnAttribute.cs
49 |
50 |
51 | ValidationAttributes\Schema\ComplexTypeAttribute.cs
52 |
53 |
54 | ValidationAttributes\Schema\ForeignKeyAttribute.cs
55 |
56 |
57 | ValidationAttributes\Schema\InversePropertyAttribute.cs
58 |
59 |
60 | ValidationAttributes\Schema\NotMappedAttribute.cs
61 |
62 |
63 | ValidationAttributes\Schema\TableAttribute.cs
64 |
65 |
66 | ValidationAttributes\CreditCardAttribute.cs
67 |
68 |
69 | ValidationAttributes\EmailAddressAttribute.cs
70 |
71 |
72 | ValidationAttributes\MaxLengthAttribute.cs
73 |
74 |
75 | ValidationAttributes\MinLengthAttribute.cs
76 |
77 |
78 | ValidationAttributes\PhoneAttribute.cs
79 |
80 |
81 | ValidationAttributes\UrlAttribute.cs
82 |
83 |
84 |
85 | True
86 | True
87 | DataAnnotationsResources.resx
88 |
89 |
90 |
91 |
92 |
93 | ResXFileCodeGenerator
94 | DataAnnotationsResources.Designer.cs
95 |
96 |
97 |
98 |
105 |
--------------------------------------------------------------------------------
/Portable.DataAnnotations.Net40/Properties/AssemblyInfo.cs:
--------------------------------------------------------------------------------
1 | using System.Reflection;
2 | using System.Runtime.CompilerServices;
3 | using System.Runtime.InteropServices;
4 |
5 | // General Information about an assembly is controlled through the following
6 | // set of attributes. Change these attribute values to modify the information
7 | // associated with an assembly.
8 | [assembly: AssemblyTitle("Portable.DataAnnotations.Net40")]
9 | [assembly: AssemblyDescription("")]
10 | [assembly: AssemblyConfiguration("")]
11 | [assembly: AssemblyCompany("")]
12 | [assembly: AssemblyProduct("Portable.DataAnnotations.Net40")]
13 | [assembly: AssemblyCopyright("Copyright © 2015")]
14 | [assembly: AssemblyTrademark("")]
15 | [assembly: AssemblyCulture("")]
16 |
17 | // Setting ComVisible to false makes the types in this assembly not visible
18 | // to COM components. If you need to access a type in this assembly from
19 | // COM, set the ComVisible attribute to true on that type.
20 | [assembly: ComVisible(false)]
21 |
22 | // The following GUID is for the ID of the typelib if this project is exposed to COM
23 | [assembly: Guid("9d907d4d-ebe8-4134-b4df-8ae30ef036be")]
24 |
25 | // Version information for an assembly consists of the following four values:
26 | //
27 | // Major Version
28 | // Minor Version
29 | // Build Number
30 | // Revision
31 | //
32 | // You can specify all the values or you can default the Build and Revision Numbers
33 | // by using the '*' as shown below:
34 | // [assembly: AssemblyVersion("1.0.*")]
35 | [assembly: AssemblyVersion("1.0.0.0")]
36 | [assembly: AssemblyFileVersion("1.0.0.0")]
37 |
--------------------------------------------------------------------------------
/Portable.DataAnnotations.Net40/TypeForwards.cs:
--------------------------------------------------------------------------------
1 | [assembly: System.Runtime.CompilerServices.TypeForwardedToAttribute(typeof(System.ComponentModel.DataAnnotations.AssociationAttribute))]
2 | [assembly: System.Runtime.CompilerServices.TypeForwardedToAttribute(typeof(System.ComponentModel.DataAnnotations.ConcurrencyCheckAttribute))]
3 | [assembly: System.Runtime.CompilerServices.TypeForwardedToAttribute(typeof(System.ComponentModel.DataAnnotations.CustomValidationAttribute))]
4 | [assembly: System.Runtime.CompilerServices.TypeForwardedToAttribute(typeof(System.ComponentModel.DataAnnotations.DataType))]
5 | [assembly: System.Runtime.CompilerServices.TypeForwardedToAttribute(typeof(System.ComponentModel.DataAnnotations.DataTypeAttribute))]
6 | [assembly: System.Runtime.CompilerServices.TypeForwardedToAttribute(typeof(System.ComponentModel.DataAnnotations.DisplayAttribute))]
7 | [assembly: System.Runtime.CompilerServices.TypeForwardedToAttribute(typeof(System.ComponentModel.DataAnnotations.DisplayColumnAttribute))]
8 | [assembly: System.Runtime.CompilerServices.TypeForwardedToAttribute(typeof(System.ComponentModel.DataAnnotations.DisplayFormatAttribute))]
9 | [assembly: System.Runtime.CompilerServices.TypeForwardedToAttribute(typeof(System.ComponentModel.DataAnnotations.EditableAttribute))]
10 | [assembly: System.Runtime.CompilerServices.TypeForwardedToAttribute(typeof(System.ComponentModel.DataAnnotations.EnumDataTypeAttribute))]
11 | [assembly: System.Runtime.CompilerServices.TypeForwardedToAttribute(typeof(System.ComponentModel.DataAnnotations.FilterUIHintAttribute))]
12 | [assembly: System.Runtime.CompilerServices.TypeForwardedToAttribute(typeof(System.ComponentModel.DataAnnotations.KeyAttribute))]
13 | [assembly: System.Runtime.CompilerServices.TypeForwardedToAttribute(typeof(System.ComponentModel.DataAnnotations.RangeAttribute))]
14 | [assembly: System.Runtime.CompilerServices.TypeForwardedToAttribute(typeof(System.ComponentModel.DataAnnotations.RegularExpressionAttribute))]
15 | [assembly: System.Runtime.CompilerServices.TypeForwardedToAttribute(typeof(System.ComponentModel.DataAnnotations.RequiredAttribute))]
16 | [assembly: System.Runtime.CompilerServices.TypeForwardedToAttribute(typeof(System.ComponentModel.DataAnnotations.StringLengthAttribute))]
17 | [assembly: System.Runtime.CompilerServices.TypeForwardedToAttribute(typeof(System.ComponentModel.DataAnnotations.TimestampAttribute))]
18 | [assembly: System.Runtime.CompilerServices.TypeForwardedToAttribute(typeof(System.ComponentModel.DataAnnotations.UIHintAttribute))]
19 | [assembly: System.Runtime.CompilerServices.TypeForwardedToAttribute(typeof(System.ComponentModel.DataAnnotations.ValidationAttribute))]
20 | [assembly: System.Runtime.CompilerServices.TypeForwardedToAttribute(typeof(System.ComponentModel.DataAnnotations.ValidationContext))]
21 | [assembly: System.Runtime.CompilerServices.TypeForwardedToAttribute(typeof(System.ComponentModel.DataAnnotations.ValidationException))]
22 | [assembly: System.Runtime.CompilerServices.TypeForwardedToAttribute(typeof(System.ComponentModel.DataAnnotations.ValidationResult))]
23 | [assembly: System.Runtime.CompilerServices.TypeForwardedToAttribute(typeof(System.ComponentModel.DataAnnotations.Validator))]
24 | [assembly: System.Runtime.CompilerServices.TypeForwardedToAttribute(typeof(System.ComponentModel.DataAnnotations.IValidatableObject))]
25 | [assembly: System.Runtime.CompilerServices.TypeForwardedToAttribute(typeof(System.ComponentModel.DataAnnotations.MetadataTypeAttribute))]
--------------------------------------------------------------------------------
/Portable.DataAnnotations.Net40Portable/Portable.DataAnnotations.Net40Portable.csproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | 10.0
6 | Debug
7 | AnyCPU
8 | {687A452E-572F-45D6-A295-49177D841590}
9 | Library
10 | Properties
11 | System.ComponentModel.DataAnnotations
12 | Portable.DataAnnotations
13 | en-US
14 | 512
15 | {786C830F-07A1-408B-BD7F-6EE04809D6DB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}
16 | Profile328
17 | v4.0
18 |
19 |
20 | true
21 | full
22 | false
23 | bin\Debug\
24 | TRACE;DEBUG;NET40
25 | prompt
26 | 4
27 |
28 |
29 | pdbonly
30 | true
31 | bin\Release\
32 | TRACE;NET40
33 | prompt
34 | 4
35 |
36 |
37 |
38 | DataType.cs
39 |
40 |
41 | GlobalSuppressions.cs
42 |
43 |
44 | IValidatableObject.cs
45 |
46 |
47 | LocalizableString.cs
48 |
49 |
50 | ValidationAttributeStore.cs
51 |
52 |
53 | ValidationAttributes\AssociationAttribute.cs
54 |
55 |
56 | ValidationAttributes\ConcurrencyCheckAttribute.cs
57 |
58 |
59 | ValidationAttributes\CustomValidationAttribute.cs
60 |
61 |
62 | ValidationAttributes\DataTypeAttribute.cs
63 |
64 |
65 | ValidationAttributes\DisplayAttribute.cs
66 |
67 |
68 | ValidationAttributes\DisplayColumnAttribute.cs
69 |
70 |
71 | ValidationAttributes\DisplayFormatAttribute.cs
72 |
73 |
74 | ValidationAttributes\EditableAttribute.cs
75 |
76 |
77 | ValidationAttributes\EnumDataTypeAttribute.cs
78 |
79 |
80 | ValidationAttributes\FilterUIHintAttribute.cs
81 |
82 |
83 | ValidationAttributes\KeyAttribute.cs
84 |
85 |
86 | ValidationAttributes\MetadataTypeAttribute.cs
87 |
88 |
89 | ValidationAttributes\RangeAttribute.cs
90 |
91 |
92 | ValidationAttributes\RegularExpressionAttribute.cs
93 |
94 |
95 | ValidationAttributes\RequiredAttribute.cs
96 |
97 |
98 | ValidationAttributes\StringLengthAttribute.cs
99 |
100 |
101 | ValidationAttributes\TimestampAttribute.cs
102 |
103 |
104 | ValidationAttributes\UIHintAttribute.cs
105 |
106 |
107 | ValidationAttributes\ValidationAttribute.cs
108 |
109 |
110 | ValidationContext.cs
111 |
112 |
113 | ValidationException.cs
114 |
115 |
116 | ValidationResult.cs
117 |
118 |
119 | Validator.cs
120 |
121 |
122 |
123 | True
124 | True
125 | DataAnnotationsResources.resx
126 |
127 |
128 |
129 |
130 | ResXFileCodeGenerator
131 | DataAnnotationsResources.Designer.cs
132 |
133 |
134 |
135 |
142 |
--------------------------------------------------------------------------------
/Portable.DataAnnotations.Net40Portable/Properties/AssemblyInfo.cs:
--------------------------------------------------------------------------------
1 | using System.Resources;
2 | using System.Reflection;
3 | using System.Runtime.CompilerServices;
4 | using System.Runtime.InteropServices;
5 |
6 | // General Information about an assembly is controlled through the following
7 | // set of attributes. Change these attribute values to modify the information
8 | // associated with an assembly.
9 | [assembly: AssemblyTitle("Portable.DataAnnotations.Net40Portable")]
10 | [assembly: AssemblyDescription("")]
11 | [assembly: AssemblyConfiguration("")]
12 | [assembly: AssemblyCompany("")]
13 | [assembly: AssemblyProduct("Portable.DataAnnotations.Net40Portable")]
14 | [assembly: AssemblyCopyright("Copyright © 2015")]
15 | [assembly: AssemblyTrademark("")]
16 | [assembly: AssemblyCulture("")]
17 | [assembly: NeutralResourcesLanguage("en")]
18 |
19 | // Version information for an assembly consists of the following four values:
20 | //
21 | // Major Version
22 | // Minor Version
23 | // Build Number
24 | // Revision
25 | //
26 | // You can specify all the values or you can default the Build and Revision Numbers
27 | // by using the '*' as shown below:
28 | // [assembly: AssemblyVersion("1.0.*")]
29 | [assembly: AssemblyVersion("1.0.0.0")]
30 | [assembly: AssemblyFileVersion("1.0.0.0")]
31 |
--------------------------------------------------------------------------------
/Portable.DataAnnotations.Net45/Portable.DataAnnotations.Net45.csproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | Debug
6 | AnyCPU
7 | {24BB9632-F412-4633-80D5-166A0EE44933}
8 | Library
9 | Properties
10 | System.ComponentModel.DataAnnotations
11 | Portable.DataAnnotations
12 | v4.5
13 | 512
14 |
15 |
16 |
17 | true
18 | full
19 | false
20 | bin\Debug\
21 | DEBUG;TRACE
22 | prompt
23 | 4
24 |
25 |
26 | pdbonly
27 | true
28 | bin\Release\
29 | TRACE
30 | prompt
31 | 4
32 |
33 |
34 |
35 |
36 |
37 |
38 |
39 |
40 |
41 |
42 |
43 |
44 |
45 |
46 |
47 |
48 |
55 |
--------------------------------------------------------------------------------
/Portable.DataAnnotations.Net45/Properties/AssemblyInfo.cs:
--------------------------------------------------------------------------------
1 | using System.Reflection;
2 | using System.Runtime.CompilerServices;
3 | using System.Runtime.InteropServices;
4 |
5 | // General Information about an assembly is controlled through the following
6 | // set of attributes. Change these attribute values to modify the information
7 | // associated with an assembly.
8 | [assembly: AssemblyTitle("Portable.DataAnnotations.Net45")]
9 | [assembly: AssemblyDescription("")]
10 | [assembly: AssemblyConfiguration("")]
11 | [assembly: AssemblyCompany("")]
12 | [assembly: AssemblyProduct("Portable.DataAnnotations.Net45")]
13 | [assembly: AssemblyCopyright("Copyright © 2015")]
14 | [assembly: AssemblyTrademark("")]
15 | [assembly: AssemblyCulture("")]
16 |
17 | // Setting ComVisible to false makes the types in this assembly not visible
18 | // to COM components. If you need to access a type in this assembly from
19 | // COM, set the ComVisible attribute to true on that type.
20 | [assembly: ComVisible(false)]
21 |
22 | // The following GUID is for the ID of the typelib if this project is exposed to COM
23 | [assembly: Guid("28b11e2d-fcd9-4ea0-8f38-8ecb8685d5eb")]
24 |
25 | // Version information for an assembly consists of the following four values:
26 | //
27 | // Major Version
28 | // Minor Version
29 | // Build Number
30 | // Revision
31 | //
32 | // You can specify all the values or you can default the Build and Revision Numbers
33 | // by using the '*' as shown below:
34 | // [assembly: AssemblyVersion("1.0.*")]
35 | [assembly: AssemblyVersion("1.0.0.0")]
36 | [assembly: AssemblyFileVersion("1.0.0.0")]
37 |
--------------------------------------------------------------------------------
/Portable.DataAnnotations.Net45/TypeForwards.cs:
--------------------------------------------------------------------------------
1 | [assembly: System.Runtime.CompilerServices.TypeForwardedToAttribute(typeof(System.ComponentModel.DataAnnotations.AssociationAttribute))]
2 | [assembly: System.Runtime.CompilerServices.TypeForwardedToAttribute(typeof(System.ComponentModel.DataAnnotations.ConcurrencyCheckAttribute))]
3 | [assembly: System.Runtime.CompilerServices.TypeForwardedToAttribute(typeof(System.ComponentModel.DataAnnotations.CustomValidationAttribute))]
4 | [assembly: System.Runtime.CompilerServices.TypeForwardedToAttribute(typeof(System.ComponentModel.DataAnnotations.DataType))]
5 | [assembly: System.Runtime.CompilerServices.TypeForwardedToAttribute(typeof(System.ComponentModel.DataAnnotations.DataTypeAttribute))]
6 | [assembly: System.Runtime.CompilerServices.TypeForwardedToAttribute(typeof(System.ComponentModel.DataAnnotations.DisplayAttribute))]
7 | [assembly: System.Runtime.CompilerServices.TypeForwardedToAttribute(typeof(System.ComponentModel.DataAnnotations.DisplayColumnAttribute))]
8 | [assembly: System.Runtime.CompilerServices.TypeForwardedToAttribute(typeof(System.ComponentModel.DataAnnotations.DisplayFormatAttribute))]
9 | [assembly: System.Runtime.CompilerServices.TypeForwardedToAttribute(typeof(System.ComponentModel.DataAnnotations.EditableAttribute))]
10 | [assembly: System.Runtime.CompilerServices.TypeForwardedToAttribute(typeof(System.ComponentModel.DataAnnotations.EnumDataTypeAttribute))]
11 | [assembly: System.Runtime.CompilerServices.TypeForwardedToAttribute(typeof(System.ComponentModel.DataAnnotations.FilterUIHintAttribute))]
12 | [assembly: System.Runtime.CompilerServices.TypeForwardedToAttribute(typeof(System.ComponentModel.DataAnnotations.KeyAttribute))]
13 | [assembly: System.Runtime.CompilerServices.TypeForwardedToAttribute(typeof(System.ComponentModel.DataAnnotations.RangeAttribute))]
14 | [assembly: System.Runtime.CompilerServices.TypeForwardedToAttribute(typeof(System.ComponentModel.DataAnnotations.RegularExpressionAttribute))]
15 | [assembly: System.Runtime.CompilerServices.TypeForwardedToAttribute(typeof(System.ComponentModel.DataAnnotations.RequiredAttribute))]
16 | [assembly: System.Runtime.CompilerServices.TypeForwardedToAttribute(typeof(System.ComponentModel.DataAnnotations.StringLengthAttribute))]
17 | [assembly: System.Runtime.CompilerServices.TypeForwardedToAttribute(typeof(System.ComponentModel.DataAnnotations.TimestampAttribute))]
18 | [assembly: System.Runtime.CompilerServices.TypeForwardedToAttribute(typeof(System.ComponentModel.DataAnnotations.UIHintAttribute))]
19 | [assembly: System.Runtime.CompilerServices.TypeForwardedToAttribute(typeof(System.ComponentModel.DataAnnotations.ValidationAttribute))]
20 | [assembly: System.Runtime.CompilerServices.TypeForwardedToAttribute(typeof(System.ComponentModel.DataAnnotations.ValidationContext))]
21 | [assembly: System.Runtime.CompilerServices.TypeForwardedToAttribute(typeof(System.ComponentModel.DataAnnotations.ValidationException))]
22 | [assembly: System.Runtime.CompilerServices.TypeForwardedToAttribute(typeof(System.ComponentModel.DataAnnotations.ValidationResult))]
23 | [assembly: System.Runtime.CompilerServices.TypeForwardedToAttribute(typeof(System.ComponentModel.DataAnnotations.Validator))]
24 | [assembly: System.Runtime.CompilerServices.TypeForwardedToAttribute(typeof(System.ComponentModel.DataAnnotations.IValidatableObject))]
25 | [assembly: System.Runtime.CompilerServices.TypeForwardedToAttribute(typeof(System.ComponentModel.DataAnnotations.Schema.DatabaseGeneratedOption))]
26 | [assembly: System.Runtime.CompilerServices.TypeForwardedToAttribute(typeof(System.ComponentModel.DataAnnotations.Schema.DatabaseGeneratedAttribute))]
27 |
28 | [assembly: System.Runtime.CompilerServices.TypeForwardedToAttribute(typeof(System.ComponentModel.DataAnnotations.BindableTypeAttribute))]
29 | [assembly: System.Runtime.CompilerServices.TypeForwardedToAttribute(typeof(System.ComponentModel.DataAnnotations.CreditCardAttribute))]
30 | [assembly: System.Runtime.CompilerServices.TypeForwardedToAttribute(typeof(System.ComponentModel.DataAnnotations.EmailAddressAttribute))]
31 | [assembly: System.Runtime.CompilerServices.TypeForwardedToAttribute(typeof(System.ComponentModel.DataAnnotations.MaxLengthAttribute))]
32 | [assembly: System.Runtime.CompilerServices.TypeForwardedToAttribute(typeof(System.ComponentModel.DataAnnotations.MetadataTypeAttribute))]
33 | [assembly: System.Runtime.CompilerServices.TypeForwardedToAttribute(typeof(System.ComponentModel.DataAnnotations.MinLengthAttribute))]
34 | [assembly: System.Runtime.CompilerServices.TypeForwardedToAttribute(typeof(System.ComponentModel.DataAnnotations.PhoneAttribute))]
35 | [assembly: System.Runtime.CompilerServices.TypeForwardedToAttribute(typeof(System.ComponentModel.DataAnnotations.UrlAttribute))]
36 |
37 | [assembly: System.Runtime.CompilerServices.TypeForwardedToAttribute(typeof(System.ComponentModel.DataAnnotations.Schema.ColumnAttribute))]
38 | [assembly: System.Runtime.CompilerServices.TypeForwardedToAttribute(typeof(System.ComponentModel.DataAnnotations.Schema.ComplexTypeAttribute))]
39 | [assembly: System.Runtime.CompilerServices.TypeForwardedToAttribute(typeof(System.ComponentModel.DataAnnotations.Schema.ForeignKeyAttribute))]
40 | [assembly: System.Runtime.CompilerServices.TypeForwardedToAttribute(typeof(System.ComponentModel.DataAnnotations.Schema.InversePropertyAttribute))]
41 | [assembly: System.Runtime.CompilerServices.TypeForwardedToAttribute(typeof(System.ComponentModel.DataAnnotations.Schema.NotMappedAttribute))]
42 | [assembly: System.Runtime.CompilerServices.TypeForwardedToAttribute(typeof(System.ComponentModel.DataAnnotations.Schema.TableAttribute))]
43 |
44 |
45 |
--------------------------------------------------------------------------------
/Portable.DataAnnotations.Net45Portable/DataType.cs:
--------------------------------------------------------------------------------
1 | namespace System.ComponentModel.DataAnnotations
2 | {
3 | ///
4 | /// Enumeration of logical data types that may appear in
5 | ///
6 | public enum DataType
7 | {
8 | ///
9 | /// Custom data type, not one of the static data types we know
10 | ///
11 | Custom,
12 |
13 | ///
14 | /// DateTime data type
15 | ///
16 | DateTime,
17 |
18 | ///
19 | /// Date data type
20 | ///
21 | Date,
22 |
23 | ///
24 | /// Time data type
25 | ///
26 | Time,
27 |
28 | ///
29 | /// Duration data type
30 | ///
31 | Duration,
32 |
33 | ///
34 | /// Phone number data type
35 | ///
36 | PhoneNumber,
37 |
38 | ///
39 | /// Currency data type
40 | ///
41 | Currency,
42 |
43 | ///
44 | /// Plain text data type
45 | ///
46 | Text,
47 |
48 | ///
49 | /// Html data type
50 | ///
51 | Html,
52 |
53 | ///
54 | /// Multiline text data type
55 | ///
56 | MultilineText,
57 |
58 | ///
59 | /// Email address data type
60 | ///
61 | EmailAddress,
62 |
63 | ///
64 | /// Password data type -- do not echo in UI
65 | ///
66 | Password,
67 |
68 | ///
69 | /// URL data type
70 | ///
71 | Url,
72 |
73 | ///
74 | /// URL to an Image -- to be displayed as an image instead of text
75 | ///
76 | ImageUrl,
77 |
78 | /////
79 | ///// Credit card data type
80 | /////
81 | //CreditCard,
82 |
83 | /////
84 | ///// Postal code data type
85 | /////
86 | //PostalCode,
87 |
88 | /////
89 | ///// File upload data type
90 | /////
91 | //Upload
92 | }
93 | }
--------------------------------------------------------------------------------
/Portable.DataAnnotations.Net45Portable/GlobalSuppressions.cs:
--------------------------------------------------------------------------------
1 | // (c) Copyright Microsoft Corporation.
2 | // This source is subject to the Microsoft Public License (Ms-PL).
3 | // Please see http://go.microsoft.com/fwlink/?LinkID=131993 for details.
4 | // All other rights reserved.
5 |
6 | using System.Diagnostics.CodeAnalysis;
7 |
8 | [assembly: SuppressMessage("General", "SWC1001:XmlDocumentationCommentShouldBeSpelledCorrectly", MessageId = "globalizable", Justification = "Spelled correctly.")]
9 | [assembly: SuppressMessage("General", "SWC1001:XmlDocumentationCommentShouldBeSpelledCorrectly", MessageId = "validators", Justification = "Spelled correctly.")]
10 |
--------------------------------------------------------------------------------
/Portable.DataAnnotations.Net45Portable/IValidatableObject.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Linq;
4 | using System.Text;
5 |
6 | namespace System.ComponentModel.DataAnnotations
7 | {
8 | public interface IValidatableObject
9 | {
10 | IEnumerable Validate(ValidationContext validationContext);
11 | }
12 | }
13 |
--------------------------------------------------------------------------------
/Portable.DataAnnotations.Net45Portable/LocalizableString.cs:
--------------------------------------------------------------------------------
1 | using System.ComponentModel.DataAnnotations.Resources;
2 | using System.Globalization;
3 | using System.Reflection;
4 |
5 | namespace System.ComponentModel.DataAnnotations
6 | {
7 | ///
8 | /// A helper class for providing a localizable string property.
9 | /// This class is currently compiled in both System.Web.dll and System.ComponentModel.DataAnnotations.dll.
10 | ///
11 | internal class LocalizableString
12 | {
13 | #region Member fields
14 |
15 | private string _propertyName;
16 | private string _propertyValue;
17 | private Type _resourceType;
18 |
19 | private Func _cachedResult;
20 |
21 | #endregion
22 |
23 | #region All Constructors
24 |
25 | ///
26 | /// Constructs a localizable string, specifying the property name associated
27 | /// with this item. The value will be used
28 | /// within any exceptions thrown as a result of localization failures.
29 | ///
30 | /// The name of the property being localized. This name
31 | /// will be used within exceptions thrown as a result of localization failures.
32 | public LocalizableString(string propertyName)
33 | {
34 | this._propertyName = propertyName;
35 | }
36 |
37 | #endregion
38 |
39 | #region Properties
40 |
41 | ///
42 | /// Gets or sets the value of this localizable string. This value can be
43 | /// either the literal, non-localized value, or it can be a resource name
44 | /// found on the resource type supplied to .
45 | ///
46 | public string Value
47 | {
48 | get
49 | {
50 | return this._propertyValue;
51 | }
52 | set
53 | {
54 | if (this._propertyValue != value)
55 | {
56 | this.ClearCache();
57 | this._propertyValue = value;
58 | }
59 | }
60 | }
61 |
62 | ///
63 | /// Gets or sets the resource type to be used for localization.
64 | ///
65 | public Type ResourceType
66 | {
67 | get
68 | {
69 | return this._resourceType;
70 | }
71 | set
72 | {
73 | if (this._resourceType != value)
74 | {
75 | this.ClearCache();
76 | this._resourceType = value;
77 | }
78 | }
79 | }
80 |
81 | #endregion
82 |
83 | #region Methods
84 |
85 | ///
86 | /// Clears any cached values, forcing to
87 | /// perform evaluation.
88 | ///
89 | private void ClearCache()
90 | {
91 | this._cachedResult = null;
92 | }
93 |
94 | ///
95 | /// Gets the potentially localized value.
96 | ///
97 | ///
98 | /// If has been specified and is not
99 | /// null, then localization will occur and the localized value will be returned.
100 | ///
101 | /// If is null then will be returned
102 | /// as a literal, non-localized string.
103 | ///
104 | ///
105 | ///
106 | /// Thrown if localization fails. This can occur if has been
107 | /// specified, is not null, but the resource could not be
108 | /// accessed. must be a public class, and
109 | /// must be the name of a public static string property that contains a getter.
110 | ///
111 | ///
112 | /// Returns the potentially localized value.
113 | ///
114 | public string GetLocalizableValue()
115 | {
116 | if (this._cachedResult == null)
117 | {
118 | // If the property value is null, then just cache that value
119 | // If the resource type is null, then property value is literal, so cache it
120 | if (this._propertyValue == null || this._resourceType == null)
121 | {
122 | this._cachedResult = () => this._propertyValue;
123 | }
124 | else
125 | {
126 | // Get the property from the resource type for this resource key
127 | PropertyInfo property = this._resourceType.GetProperty(this._propertyValue);
128 |
129 | // We need to detect bad configurations so that we can throw exceptions accordingly
130 | bool badlyConfigured = false;
131 |
132 | // Make sure we found the property and it's the correct type, and that the type itself is public
133 | if (!this._resourceType.IsVisible || property == null || property.PropertyType != typeof(string))
134 | {
135 | badlyConfigured = true;
136 | }
137 | else
138 | {
139 | // Ensure the getter for the property is available as public static
140 | MethodInfo getter = property.GetGetMethod();
141 |
142 | if (getter == null || !(getter.IsPublic && getter.IsStatic))
143 | {
144 | badlyConfigured = true;
145 | }
146 | }
147 |
148 | // If the property is not configured properly, then throw a missing member exception
149 | if (badlyConfigured)
150 | {
151 | string exceptionMessage = String.Format(CultureInfo.CurrentCulture,
152 | DataAnnotationsResources.LocalizableString_LocalizationFailed,
153 | this._propertyName, this._resourceType.FullName, this._propertyValue);
154 | this._cachedResult = () => { throw new InvalidOperationException(exceptionMessage); };
155 | }
156 | else
157 | {
158 | // We have a valid property, so cache the resource
159 | this._cachedResult = () => (string)property.GetValue(null, null);
160 | }
161 | }
162 | }
163 |
164 | // Return the cached result
165 | return this._cachedResult();
166 | }
167 |
168 | #endregion
169 | }
170 | }
--------------------------------------------------------------------------------
/Portable.DataAnnotations.Net45Portable/Portable.DataAnnotations.Net45Portable.csproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | 10.0
6 | Debug
7 | AnyCPU
8 | {A438D987-9708-4DF4-AF3F-16C03B83108E}
9 | Library
10 | Properties
11 | System.ComponentModel.DataAnnotations
12 | Portable.DataAnnotations
13 | en-US
14 | 512
15 | {786C830F-07A1-408B-BD7F-6EE04809D6DB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}
16 | Profile344
17 | v4.0
18 |
19 |
20 | true
21 | full
22 | false
23 | bin\Debug\
24 | TRACE;DEBUG
25 | prompt
26 | 4
27 |
28 |
29 | pdbonly
30 | true
31 | bin\Release\
32 | TRACE
33 | prompt
34 | 4
35 |
36 |
37 |
38 |
39 |
40 |
41 |
42 |
43 |
44 | True
45 | True
46 | DataAnnotationsResources.resx
47 |
48 |
49 |
50 |
51 |
52 |
53 |
54 |
55 |
56 |
57 |
58 |
59 |
60 |
61 |
62 |
63 |
64 |
65 |
66 |
67 |
68 |
69 |
70 |
71 |
72 |
73 |
74 |
75 |
76 |
77 |
78 |
79 |
80 |
81 |
82 |
83 |
84 |
85 |
86 |
87 |
88 |
89 |
90 | ResXFileCodeGenerator
91 | DataAnnotationsResources.Designer.cs
92 |
93 |
94 |
95 |
102 |
--------------------------------------------------------------------------------
/Portable.DataAnnotations.Net45Portable/Properties/AssemblyInfo.cs:
--------------------------------------------------------------------------------
1 | using System.Resources;
2 | using System.Reflection;
3 | using System.Runtime.CompilerServices;
4 | using System.Runtime.InteropServices;
5 |
6 | // General Information about an assembly is controlled through the following
7 | // set of attributes. Change these attribute values to modify the information
8 | // associated with an assembly.
9 | [assembly: AssemblyTitle("Portable.DataAnnotations")]
10 | [assembly: AssemblyDescription("")]
11 | [assembly: AssemblyConfiguration("")]
12 | [assembly: AssemblyCompany("")]
13 | [assembly: AssemblyProduct("Portable.DataAnnotations")]
14 | [assembly: AssemblyCopyright("Copyright © 2015")]
15 | [assembly: AssemblyTrademark("")]
16 | [assembly: AssemblyCulture("")]
17 | [assembly: NeutralResourcesLanguage("en")]
18 |
19 | // Version information for an assembly consists of the following four values:
20 | //
21 | // Major Version
22 | // Minor Version
23 | // Build Number
24 | // Revision
25 | //
26 | // You can specify all the values or you can default the Build and Revision Numbers
27 | // by using the '*' as shown below:
28 | // [assembly: AssemblyVersion("1.0.*")]
29 | [assembly: AssemblyVersion("1.0.0.0")]
30 | [assembly: AssemblyFileVersion("1.0.0.0")]
31 |
--------------------------------------------------------------------------------
/Portable.DataAnnotations.Net45Portable/ValidationAttributes/AssociationAttribute.cs:
--------------------------------------------------------------------------------
1 | using System.Collections.Generic;
2 |
3 | namespace System.ComponentModel.DataAnnotations
4 | {
5 | ///
6 | /// Used to mark an Entity member as an association
7 | ///
8 | [AttributeUsage(AttributeTargets.Field | AttributeTargets.Property, AllowMultiple = false, Inherited = true)]
9 | public sealed class AssociationAttribute : Attribute
10 | {
11 | private string name;
12 | private string thisKey;
13 | private string otherKey;
14 | private bool isForeignKey;
15 |
16 | ///
17 | /// Full form of constructor
18 | ///
19 | /// The name of the association. For bi-directional associations, the name must
20 | /// be the same on both sides of the association
21 | /// Comma separated list of the property names of the key values
22 | /// on this side of the association
23 | /// Comma separated list of the property names of the key values
24 | /// on the other side of the association
25 | public AssociationAttribute(string name, string thisKey, string otherKey)
26 | {
27 | this.name = name;
28 | this.thisKey = thisKey;
29 | this.otherKey = otherKey;
30 | }
31 |
32 | ///
33 | /// Gets the name of the association. For bi-directional associations, the name must
34 | /// be the same on both sides of the association
35 | ///
36 | public string Name
37 | {
38 | get { return this.name; }
39 | }
40 |
41 | ///
42 | /// Gets a comma separated list of the property names of the key values
43 | /// on this side of the association
44 | ///
45 | public string ThisKey
46 | {
47 | get
48 | {
49 | return this.thisKey;
50 | }
51 | }
52 |
53 | ///
54 | /// Gets a comma separated list of the property names of the key values
55 | /// on the other side of the association
56 | ///
57 | public string OtherKey
58 | {
59 | get
60 | {
61 | return this.otherKey;
62 | }
63 | }
64 |
65 | ///
66 | /// Gets or sets a value indicating whether this association member represents the foreign key
67 | /// side of an association
68 | ///
69 | public bool IsForeignKey
70 | {
71 | get
72 | {
73 | return this.isForeignKey;
74 | }
75 | set
76 | {
77 | this.isForeignKey = value;
78 | }
79 | }
80 |
81 | ///
82 | /// Gets the collection of individual key members specified in the ThisKey string.
83 | ///
84 | public IEnumerable ThisKeyMembers
85 | {
86 | get
87 | {
88 | return GetKeyMembers(this.ThisKey);
89 | }
90 | }
91 |
92 | ///
93 | /// Gets the collection of individual key members specified in the OtherKey string.
94 | ///
95 | public IEnumerable OtherKeyMembers
96 | {
97 | get
98 | {
99 | return GetKeyMembers(this.OtherKey);
100 | }
101 | }
102 |
103 | ///
104 | /// Parses the comma delimited key specified
105 | ///
106 | /// The key to parse
107 | /// Array of individual key members
108 | private static string[] GetKeyMembers(string key)
109 | {
110 | return key.Replace(" ", string.Empty).Split(',');
111 | }
112 | }
113 | }
--------------------------------------------------------------------------------
/Portable.DataAnnotations.Net45Portable/ValidationAttributes/BindableTypeAttribute.cs:
--------------------------------------------------------------------------------
1 | namespace System.ComponentModel.DataAnnotations
2 | {
3 | ///
4 | /// Specifies that a type is considered a bindable type for automatic fields generation by controls like GridView / DetailsView.
5 | ///
6 | [AttributeUsage(AttributeTargets.Class | AttributeTargets.Enum | AttributeTargets.Struct, AllowMultiple = false, Inherited = true)]
7 | public sealed class BindableTypeAttribute : Attribute
8 | {
9 |
10 | public BindableTypeAttribute()
11 | {
12 | IsBindable = true;
13 | }
14 |
15 | ///
16 | /// Indicates whether the type should be considered Bindable or not. The default value is true when the attribute is specified.
17 | ///
18 | public bool IsBindable
19 | {
20 | get;
21 | set;
22 | }
23 | }
24 | }
--------------------------------------------------------------------------------
/Portable.DataAnnotations.Net45Portable/ValidationAttributes/ConcurrencyCheckAttribute.cs:
--------------------------------------------------------------------------------
1 | namespace System.ComponentModel.DataAnnotations
2 | {
3 | ///
4 | /// This attribute is used to mark the members of a Type that participate in
5 | /// optimistic concurrency checks.
6 | ///
7 | [AttributeUsage(AttributeTargets.Property | AttributeTargets.Field, AllowMultiple = false, Inherited = true)]
8 | public sealed class ConcurrencyCheckAttribute : Attribute
9 | {
10 | }
11 | }
--------------------------------------------------------------------------------
/Portable.DataAnnotations.Net45Portable/ValidationAttributes/CreditCardAttribute.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.ComponentModel.DataAnnotations;
4 | using System.ComponentModel.DataAnnotations.Resources;
5 | using System.Linq;
6 | using System.Text;
7 |
8 | namespace System.ComponentModel.DataAnnotations
9 | {
10 | [AttributeUsage(AttributeTargets.Property | AttributeTargets.Field | AttributeTargets.Parameter, AllowMultiple = false)]
11 | public sealed class CreditCardAttribute : DataTypeAttribute
12 | {
13 | public CreditCardAttribute()
14 | : base(DataType.Custom)
15 | {
16 | var att = new RangeAttribute(0, 100);
17 | ErrorMessage = DataAnnotationsResources.CreditCardAttribute_Invalid;
18 | }
19 |
20 | internal override bool IsValid(object value)
21 | {
22 | if (value == null)
23 | {
24 | return true;
25 | }
26 |
27 | string ccValue = value as string;
28 | if (ccValue == null)
29 | {
30 | return false;
31 | }
32 | ccValue = ccValue.Replace("-", "");
33 | ccValue = ccValue.Replace(" ", "");
34 |
35 | int checksum = 0;
36 | bool evenDigit = false;
37 |
38 | // http://www.beachnet.com/~hstiles/cardtype.html
39 | foreach (char digit in Reverse(ccValue))
40 | {
41 | if (digit < '0' || digit > '9')
42 | {
43 | return false;
44 | }
45 |
46 | int digitValue = (digit - '0') * (evenDigit ? 2 : 1);
47 | evenDigit = !evenDigit;
48 |
49 | while (digitValue > 0)
50 | {
51 | checksum += digitValue % 10;
52 | digitValue /= 10;
53 | }
54 | }
55 |
56 | return (checksum % 10) == 0;
57 | }
58 |
59 | private static string Reverse(string input)
60 | {
61 | StringBuilder sb = new StringBuilder(input.Length);
62 | for (int i = input.Length - 1; i >= 0; i--)
63 | {
64 | sb.Append(input[i]);
65 | }
66 | return sb.ToString();
67 | }
68 | }
69 | }
--------------------------------------------------------------------------------
/Portable.DataAnnotations.Net45Portable/ValidationAttributes/DataTypeAttribute.cs:
--------------------------------------------------------------------------------
1 | using System.ComponentModel.DataAnnotations.Resources;
2 | using System.Diagnostics.CodeAnalysis;
3 | using System.Globalization;
4 |
5 | namespace System.ComponentModel.DataAnnotations
6 | {
7 | ///
8 | /// Allows for clarification of the represented by a given
9 | /// property (such as
10 | /// or )
11 | ///
12 | [AttributeUsage(AttributeTargets.Property | AttributeTargets.Field | AttributeTargets.Method | AttributeTargets.Parameter, AllowMultiple = false)]
13 | [SuppressMessage("Microsoft.Performance", "CA1813:AvoidUnsealedAttributes", Justification = "We want users to be able to extend this class")]
14 | public class DataTypeAttribute : ValidationAttribute
15 | {
16 | ///
17 | /// Gets the DataType. If it equals DataType.Custom, should also be retrieved.
18 | ///
19 | public DataType DataType { get; private set; }
20 |
21 | ///
22 | /// Gets the string representing a custom data type. Returns a non-null value only if is DataType.Custom.
23 | ///
24 | public string CustomDataType { get; private set; }
25 |
26 | ///
27 | /// Return the name of the data type, either using the enum or string
28 | ///
29 | /// The name of the data type enum
30 | /// is thrown if the current attribute is ill-formed.
31 | [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Design", "CA1024:UsePropertiesWhereAppropriate", Justification = "This method throws an exception if the properties have not been configured correctly")]
32 | public virtual string GetDataTypeName()
33 | {
34 | this.EnsureValidDataType();
35 |
36 | if (DataType == DataType.Custom)
37 | {
38 | // If it's a custom type string, use it as the template name
39 | return this.CustomDataType;
40 | }
41 | else
42 | {
43 | // If it's an enum, turn it into a string
44 | // Use the cached array with enum string values instead of ToString() as the latter is too slow
45 | return _dataTypeStrings[(int)DataType];
46 | }
47 | }
48 |
49 | ///
50 | /// Gets the default display format that gets used along with this DataType.
51 | ///
52 | public DisplayFormatAttribute DisplayFormat { get; protected set; }
53 |
54 | ///
55 | /// Constructor that accepts a data type enumeration
56 | ///
57 | /// The enum value indicating the type to apply.
58 | public DataTypeAttribute(DataType dataType)
59 | {
60 | DataType = dataType;
61 |
62 | // Set some DisplayFormat for a few specific data types
63 | switch (dataType)
64 | {
65 | case DataType.Date:
66 | this.DisplayFormat = new DisplayFormatAttribute();
67 | this.DisplayFormat.DataFormatString = "{0:d}";
68 | this.DisplayFormat.ApplyFormatInEditMode = true;
69 | break;
70 | case DataType.Time:
71 | this.DisplayFormat = new DisplayFormatAttribute();
72 | this.DisplayFormat.DataFormatString = "{0:t}";
73 | this.DisplayFormat.ApplyFormatInEditMode = true;
74 | break;
75 | case DataType.Currency:
76 | this.DisplayFormat = new DisplayFormatAttribute();
77 | this.DisplayFormat.DataFormatString = "{0:C}";
78 |
79 | // Don't set ApplyFormatInEditMode for currencies because the currency
80 | // symbol can't be parsed
81 | break;
82 | }
83 | }
84 |
85 | ///
86 | /// Constructor that accepts the string name of a custom data type
87 | ///
88 | /// The string name of the custom data type.
89 | public DataTypeAttribute(string customDataType)
90 | : this(DataType.Custom)
91 | {
92 | this.CustomDataType = customDataType;
93 | }
94 |
95 | ///
96 | /// Override of
97 | ///
98 | /// This override always returns true. Subclasses should override this to provide the correct result.
99 | /// The value to validate
100 | /// Unconditionally returns true
101 | /// is thrown if the current attribute is ill-formed.
102 | internal override bool IsValid(object value)
103 | {
104 | this.EnsureValidDataType();
105 |
106 | return true;
107 | }
108 |
109 | ///
110 | /// Throws an exception if this attribute is not correctly formed
111 | ///
112 | /// is thrown if the current attribute is ill-formed.
113 | private void EnsureValidDataType()
114 | {
115 | if (this.DataType == DataType.Custom && String.IsNullOrEmpty(this.CustomDataType))
116 | {
117 | throw new InvalidOperationException(String.Format(CultureInfo.CurrentCulture, DataAnnotationsResources.DataTypeAttribute_EmptyDataTypeString));
118 | }
119 | }
120 |
121 | private static string[] _dataTypeStrings = Enum.GetNames(typeof(DataType));
122 | }
123 | }
--------------------------------------------------------------------------------
/Portable.DataAnnotations.Net45Portable/ValidationAttributes/DisplayColumnAttribute.cs:
--------------------------------------------------------------------------------
1 | using System.Diagnostics.CodeAnalysis;
2 |
3 | namespace System.ComponentModel.DataAnnotations
4 | {
5 | ///
6 | /// Sets the display column, the sort column, and the sort order for when a table is used as a parent table in FK relationships.
7 | ///
8 | [AttributeUsage(AttributeTargets.Class, Inherited = true, AllowMultiple = false)]
9 | [SuppressMessage("Microsoft.Performance", "CA1813:AvoidUnsealedAttributes", Justification = "We want users to be able to extend this class")]
10 | public class DisplayColumnAttribute : Attribute
11 | {
12 | public DisplayColumnAttribute(string displayColumn)
13 | : this(displayColumn, null)
14 | {
15 | }
16 |
17 | public DisplayColumnAttribute(string displayColumn, string sortColumn)
18 | : this(displayColumn, sortColumn, false)
19 | {
20 | }
21 |
22 | public DisplayColumnAttribute(string displayColumn, string sortColumn, bool sortDescending)
23 | {
24 | this.DisplayColumn = displayColumn;
25 | this.SortColumn = sortColumn;
26 | this.SortDescending = sortDescending;
27 | }
28 |
29 | public string DisplayColumn { get; private set; }
30 |
31 | public string SortColumn { get; private set; }
32 |
33 | public bool SortDescending { get; private set; }
34 | }
35 | }
--------------------------------------------------------------------------------
/Portable.DataAnnotations.Net45Portable/ValidationAttributes/DisplayFormatAttribute.cs:
--------------------------------------------------------------------------------
1 | using System.Diagnostics.CodeAnalysis;
2 |
3 | namespace System.ComponentModel.DataAnnotations
4 | {
5 | ///
6 | /// Allows overriding various display-related options for a given field. The options have the same meaning as in BoundField.
7 | ///
8 | [AttributeUsage(AttributeTargets.Property | AttributeTargets.Field, AllowMultiple = false)]
9 | [SuppressMessage("Microsoft.Performance", "CA1813:AvoidUnsealedAttributes", Justification = "We want users to be able to extend this class")]
10 | public class DisplayFormatAttribute : Attribute
11 | {
12 | ///
13 | /// Gets or sets the format string
14 | ///
15 | public string DataFormatString { get; set; }
16 |
17 | ///
18 | /// Gets or sets the string to display when the value is null
19 | ///
20 | public string NullDisplayText { get; set; }
21 |
22 | ///
23 | /// Gets or sets a value indicating whether empty strings should be set to null
24 | ///
25 | public bool ConvertEmptyStringToNull { get; set; }
26 |
27 | ///
28 | /// Gets or sets a value indicating whether the format string should be used in edit mode
29 | ///
30 | public bool ApplyFormatInEditMode { get; set; }
31 |
32 | #if !SILVERLIGHT
33 | ///
34 | /// Gets or sets a value indicating whether the field should be html encoded
35 | ///
36 | public bool HtmlEncode { get; set; }
37 | #endif
38 |
39 | ///
40 | /// Default constructor
41 | ///
42 | public DisplayFormatAttribute()
43 | {
44 | this.ConvertEmptyStringToNull = true; // default to true to match behavior in related components
45 |
46 | #if !SILVERLIGHT
47 | this.HtmlEncode = true; // default to true to match behavior in related components
48 | #endif
49 | }
50 | }
51 | }
--------------------------------------------------------------------------------
/Portable.DataAnnotations.Net45Portable/ValidationAttributes/EditableAttribute.cs:
--------------------------------------------------------------------------------
1 | namespace System.ComponentModel.DataAnnotations
2 | {
3 | ///
4 | /// Indicates whether the consumer of a field or property, such as a client application,
5 | /// should allow editing of the value.
6 | ///
7 | ///
8 | /// This attribute neither enforces nor guarantees editability; the underlying data
9 | /// store might allow changing the data regardless of this attribute. The presence
10 | /// of this attribute signals intent to the consumer of the attribute whethere or not
11 | /// the end user should be allowed to change the value via the client application.
12 | ///
13 | [AttributeUsage(AttributeTargets.Field | AttributeTargets.Property, AllowMultiple = false, Inherited = true)]
14 | public sealed class EditableAttribute : Attribute
15 | {
16 | ///
17 | /// Indicates whether or not the field/property allows editing of the
18 | /// value.
19 | ///
20 | ///
21 | /// When true, the field/property is editable.
22 | ///
23 | /// When false, the field/property is not editable.
24 | ///
25 | ///
26 | public bool AllowEdit { get; private set; }
27 |
28 | ///
29 | /// Indicates whether or not the field/property allows an initial value
30 | /// to be specified.
31 | ///
32 | ///
33 | /// The value of this property defaults to match the
34 | /// property value specified in the constructor.
35 | ///
36 | ///
37 | /// When true, the field/property can have its value set for
38 | /// newly constructed instances, such as during an insert operation.
39 | ///
40 | /// When false, the field/property cannot have its
41 | /// value provided for newly constructed instances, such as during
42 | /// an insert operation. This will often indicate that the value
43 | /// is auto-generated by the persistence store.
44 | ///
45 | ///
46 | public bool AllowInitialValue { get; set; }
47 |
48 | ///
49 | /// Indicate whether or not a field/property is editable.
50 | ///
51 | ///
52 | /// Indicates whether the field/property is editable. The value provided
53 | /// will apply to both and
54 | /// unless the
55 | /// property is explicitly specified.
56 | ///
57 | public EditableAttribute(bool allowEdit)
58 | {
59 | this.AllowEdit = allowEdit;
60 | this.AllowInitialValue = allowEdit;
61 | }
62 | }
63 | }
--------------------------------------------------------------------------------
/Portable.DataAnnotations.Net45Portable/ValidationAttributes/EmailAddressAttribute.cs:
--------------------------------------------------------------------------------
1 | namespace System.ComponentModel.DataAnnotations
2 | {
3 | using System;
4 | using System.ComponentModel.DataAnnotations.Resources;
5 | using System.Text.RegularExpressions;
6 |
7 | [AttributeUsage(AttributeTargets.Property | AttributeTargets.Field | AttributeTargets.Parameter, AllowMultiple = false)]
8 | public sealed class EmailAddressAttribute : DataTypeAttribute
9 | {
10 |
11 | // This attribute provides server-side email validation equivalent to jquery validate,
12 | // and therefore shares the same regular expression. See unit tests for examples.
13 | private static Regex _regex = new Regex(@"^((([a-z]|\d|[!#\$%&'\*\+\-\/=\?\^_`{\|}~]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])+(\.([a-z]|\d|[!#\$%&'\*\+\-\/=\?\^_`{\|}~]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])+)*)|((\x22)((((\x20|\x09)*(\x0d\x0a))?(\x20|\x09)+)?(([\x01-\x08\x0b\x0c\x0e-\x1f\x7f]|\x21|[\x23-\x5b]|[\x5d-\x7e]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(\\([\x01-\x09\x0b\x0c\x0d-\x7f]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF]))))*(((\x20|\x09)*(\x0d\x0a))?(\x20|\x09)+)?(\x22)))@((([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])*([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])))\.)+(([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])*([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])))\.?$", RegexOptions.IgnoreCase | RegexOptions.ExplicitCapture);
14 |
15 | public EmailAddressAttribute()
16 | : base(DataType.EmailAddress)
17 | {
18 | ErrorMessage = DataAnnotationsResources.EmailAddressAttribute_Invalid;
19 | }
20 |
21 | internal override bool IsValid(object value)
22 | {
23 | if (value == null)
24 | {
25 | return true;
26 | }
27 |
28 | string valueAsString = value as string;
29 | return valueAsString != null && _regex.Match(valueAsString).Length > 0;
30 | }
31 | }
32 | }
--------------------------------------------------------------------------------
/Portable.DataAnnotations.Net45Portable/ValidationAttributes/EnumDataTypeAttribute.cs:
--------------------------------------------------------------------------------
1 | using System.ComponentModel.DataAnnotations.Resources;
2 | using System.Diagnostics;
3 | using System.Diagnostics.CodeAnalysis;
4 | using System.Globalization;
5 |
6 | namespace System.ComponentModel.DataAnnotations
7 | {
8 | [AttributeUsage(AttributeTargets.Property | AttributeTargets.Field | AttributeTargets.Method | AttributeTargets.Parameter, AllowMultiple = false)]
9 | [SuppressMessage("Microsoft.Performance", "CA1813:AvoidUnsealedAttributes", Justification = "We want users to be able to extend this class")]
10 | public sealed class EnumDataTypeAttribute : DataTypeAttribute
11 | {
12 | public Type EnumType { get; private set; }
13 |
14 | public EnumDataTypeAttribute(Type enumType)
15 | : base("Enumeration")
16 | {
17 | this.EnumType = enumType;
18 | }
19 |
20 | internal override bool IsValid(object value)
21 | {
22 | if (this.EnumType == null)
23 | {
24 | throw new InvalidOperationException(DataAnnotationsResources.EnumDataTypeAttribute_TypeCannotBeNull);
25 | }
26 | if (!this.EnumType.IsEnum)
27 | {
28 | throw new InvalidOperationException(String.Format(CultureInfo.CurrentCulture, DataAnnotationsResources.EnumDataTypeAttribute_TypeNeedsToBeAnEnum, this.EnumType.FullName));
29 | }
30 |
31 | if (value == null)
32 | {
33 | return true;
34 | }
35 | string stringValue = value as string;
36 | if (stringValue != null && String.IsNullOrEmpty(stringValue))
37 | {
38 | return true;
39 | }
40 |
41 | Type valueType = value.GetType();
42 | if (valueType.IsEnum && this.EnumType != valueType)
43 | {
44 | // don't match a different enum that might map to the same underlying integer
45 | //
46 | return false;
47 | }
48 |
49 | if (!valueType.IsValueType && valueType != typeof(string))
50 | {
51 | // non-value types cannot be converted
52 | return false;
53 | }
54 |
55 | if (valueType == typeof(bool) ||
56 | valueType == typeof(float) ||
57 | valueType == typeof(double) ||
58 | valueType == typeof(decimal) ||
59 | valueType == typeof(char))
60 | {
61 | // non-integral types cannot be converted
62 | return false;
63 | }
64 |
65 | object convertedValue;
66 | if (valueType.IsEnum)
67 | {
68 | Debug.Assert(valueType == value.GetType(), "The valueType should equal the Type of the value");
69 | convertedValue = value;
70 | }
71 | else
72 | {
73 | try
74 | {
75 | if (stringValue != null)
76 | {
77 | convertedValue = Enum.Parse(this.EnumType, stringValue, false);
78 | }
79 | else
80 | {
81 | convertedValue = Enum.ToObject(this.EnumType, value);
82 | }
83 | }
84 | catch (ArgumentException)
85 | {
86 | //
87 | return false;
88 | }
89 | }
90 |
91 | if (IsEnumTypeInFlagsMode(this.EnumType))
92 | {
93 | //
94 |
95 |
96 |
97 | string underlying = GetUnderlyingTypeValueString(this.EnumType, convertedValue);
98 | string converted = convertedValue.ToString();
99 | return !underlying.Equals(converted);
100 | }
101 | else
102 | {
103 | return Enum.IsDefined(this.EnumType, convertedValue);
104 | }
105 | }
106 |
107 | private static bool IsEnumTypeInFlagsMode(Type enumType)
108 | {
109 | return enumType.GetCustomAttributes(typeof(FlagsAttribute), false).Length != 0;
110 | }
111 |
112 |
113 | private static string GetUnderlyingTypeValueString(Type enumType, object enumValue)
114 | {
115 | return Convert.ChangeType(enumValue, Enum.GetUnderlyingType(enumType), CultureInfo.InvariantCulture).ToString();
116 | }
117 | }
118 | }
--------------------------------------------------------------------------------
/Portable.DataAnnotations.Net45Portable/ValidationAttributes/FilterUIHintAttribute.cs:
--------------------------------------------------------------------------------
1 | using System.Collections.Generic;
2 | using System.Diagnostics.CodeAnalysis;
3 |
4 | namespace System.ComponentModel.DataAnnotations
5 | {
6 | ///
7 | /// An attribute used to specify the filtering behavior for a column.
8 | ///
9 | [SuppressMessage("Microsoft.Design", "CA1019:DefineAccessorsForAttributeArguments", Justification = "ControlParameters is exposed, just with a different type")]
10 | [AttributeUsage(AttributeTargets.Property | AttributeTargets.Field, AllowMultiple = false)]
11 | public sealed class FilterUIHintAttribute : Attribute
12 | {
13 | private UIHintAttribute.UIHintImplementation _implementation;
14 |
15 | ///
16 | /// Gets the name of the control that is most appropriate for this associated property or field
17 | ///
18 | public string FilterUIHint
19 | {
20 | get
21 | {
22 | return this._implementation.UIHint;
23 | }
24 | }
25 |
26 | ///
27 | /// Gets the name of the presentation layer that supports the control type in
28 | ///
29 | public string PresentationLayer
30 | {
31 | get
32 | {
33 | return this._implementation.PresentationLayer;
34 | }
35 | }
36 |
37 | ///
38 | /// Gets the name-value pairs used as parameters to the control's constructor
39 | ///
40 | /// is thrown if the current attribute is ill-formed.
41 | public IDictionary ControlParameters
42 | {
43 | get
44 | {
45 | return this._implementation.ControlParameters;
46 | }
47 | }
48 |
49 | ///
50 | /// Constructor that accepts the name of the control, without specifying which presentation layer to use
51 | ///
52 | /// The name of the UI control.
53 | public FilterUIHintAttribute(string filterUIHint)
54 | : this(filterUIHint, null, new object[0])
55 | {
56 | }
57 |
58 | ///
59 | /// Constructor that accepts both the name of the control as well as the presentation layer
60 | ///
61 | /// The name of the control to use
62 | /// The name of the presentation layer that supports this control
63 | public FilterUIHintAttribute(string filterUIHint, string presentationLayer)
64 | : this(filterUIHint, presentationLayer, new object[0])
65 | {
66 | }
67 |
68 | ///
69 | /// Full constructor that accepts the name of the control, presentation layer, and optional parameters
70 | /// to use when constructing the control
71 | ///
72 | /// The name of the control
73 | /// The presentation layer
74 | /// The list of parameters for the control
75 | public FilterUIHintAttribute(string filterUIHint, string presentationLayer, params object[] controlParameters)
76 | {
77 | this._implementation = new UIHintAttribute.UIHintImplementation(filterUIHint, presentationLayer, controlParameters);
78 | }
79 |
80 | ///
81 | /// Returns the hash code for this FilterUIHintAttribute.
82 | ///
83 | /// A 32-bit signed integer hash code.
84 | public override int GetHashCode()
85 | {
86 | return this._implementation.GetHashCode();
87 | }
88 |
89 | ///
90 | /// Determines whether this instance of FilterUIHintAttribute and a specified object,
91 | /// which must also be a FilterUIHintAttribute object, have the same value.
92 | ///
93 | /// An System.Object.
94 | /// true if obj is a FilterUIHintAttribute and its value is the same as this instance; otherwise, false.
95 | public override bool Equals(object obj)
96 | {
97 | var otherAttribute = obj as FilterUIHintAttribute;
98 | if (otherAttribute == null)
99 | {
100 | return false;
101 | }
102 | return this._implementation.Equals(otherAttribute._implementation);
103 | }
104 | }
105 | }
--------------------------------------------------------------------------------
/Portable.DataAnnotations.Net45Portable/ValidationAttributes/KeyAttribute.cs:
--------------------------------------------------------------------------------
1 | namespace System.ComponentModel.DataAnnotations
2 | {
3 | ///
4 | /// Used to mark one or more entity properties that provide the entity's unique identity
5 | ///
6 | [AttributeUsage(AttributeTargets.Property | AttributeTargets.Field, AllowMultiple = false, Inherited = true)]
7 | public sealed class KeyAttribute : Attribute
8 | {
9 | }
10 | }
--------------------------------------------------------------------------------
/Portable.DataAnnotations.Net45Portable/ValidationAttributes/MaxLengthAttribute.cs:
--------------------------------------------------------------------------------
1 | using System.ComponentModel.DataAnnotations.Resources;
2 | using System.Diagnostics.CodeAnalysis;
3 | using System.Globalization;
4 |
5 | namespace System.ComponentModel.DataAnnotations
6 | {
7 | ///
8 | /// Specifies the maximum length of array/string data allowed in a property.
9 | ///
10 | [AttributeUsage(AttributeTargets.Property | AttributeTargets.Field | AttributeTargets.Parameter, AllowMultiple = false)]
11 | [SuppressMessage("Microsoft.Performance", "CA1813:AvoidUnsealedAttributes", Justification = "We want users to be able to extend this class")]
12 | public class MaxLengthAttribute : ValidationAttribute
13 | {
14 | private const int MaxAllowableLength = -1;
15 |
16 | ///
17 | /// Gets the maximum allowable length of the array/string data.
18 | ///
19 | public int Length { get; private set; }
20 |
21 | ///
22 | /// Initializes a new instance of the class.
23 | ///
24 | ///
25 | /// The maximum allowable length of array/string data.
26 | /// Value must be greater than zero.
27 | ///
28 | public MaxLengthAttribute(int length)
29 | : base(() => DefaultErrorMessageString)
30 | {
31 | Length = length;
32 | }
33 |
34 | ///
35 | /// Initializes a new instance of the class.
36 | /// The maximum allowable length supported by the database will be used.
37 | ///
38 | public MaxLengthAttribute()
39 | : base(() => DefaultErrorMessageString)
40 | {
41 | Length = MaxAllowableLength;
42 | }
43 |
44 | private static string DefaultErrorMessageString
45 | {
46 | get { return DataAnnotationsResources.MaxLengthAttribute_ValidationError; }
47 | }
48 |
49 | ///
50 | /// Determines whether a specified object is valid. (Overrides )
51 | ///
52 | ///
53 | /// This method returns true if the is null.
54 | /// It is assumed the is used if the value may not be null.
55 | ///
56 | /// The object to validate.
57 | /// true if the value is null or less than or equal to the specified maximum length, otherwise false
58 | /// Length is zero or less than negative one.
59 | internal override bool IsValid(object value)
60 | {
61 | // Check the lengths for legality
62 | EnsureLegalLengths();
63 |
64 | var length = 0;
65 | // Automatically pass if value is null. RequiredAttribute should be used to assert a value is not null.
66 | if (value == null)
67 | {
68 | return true;
69 | }
70 | else
71 | {
72 | var str = value as string;
73 | if (str != null)
74 | {
75 | length = str.Length;
76 | }
77 | else
78 | {
79 | // We expect a cast exception if a non-{string|array} property was passed in.
80 | length = ((Array)value).Length;
81 | }
82 | }
83 |
84 | return MaxAllowableLength == Length || length <= Length;
85 | }
86 |
87 | ///
88 | /// Applies formatting to a specified error message. (Overrides )
89 | ///
90 | /// The name to include in the formatted string.
91 | /// A localized string to describe the maximum acceptable length.
92 | public override string FormatErrorMessage(string name)
93 | {
94 | // An error occurred, so we know the value is greater than the maximum if it was specified
95 | return string.Format(CultureInfo.CurrentCulture, ErrorMessageString, name, Length);
96 | }
97 |
98 | ///
99 | /// Checks that Length has a legal value.
100 | ///
101 | /// Length is zero or less than negative one.
102 | private void EnsureLegalLengths()
103 | {
104 | if (Length == 0 || Length < -1)
105 | {
106 | throw new InvalidOperationException(String.Format(CultureInfo.CurrentCulture, DataAnnotationsResources.MaxLengthAttribute_InvalidMaxLength));
107 | }
108 | }
109 | }
110 | }
--------------------------------------------------------------------------------
/Portable.DataAnnotations.Net45Portable/ValidationAttributes/MetadataTypeAttribute.cs:
--------------------------------------------------------------------------------
1 | using System.ComponentModel.DataAnnotations.Resources;
2 | using System;
3 |
4 | namespace System.ComponentModel.DataAnnotations
5 | {
6 | ///
7 | /// Used for associating a metadata class with the entity class.
8 | ///
9 | [AttributeUsage(AttributeTargets.Class, AllowMultiple = false)]
10 | public sealed class MetadataTypeAttribute : Attribute {
11 |
12 | private Type _metadataClassType;
13 |
14 | public Type MetadataClassType {
15 | get {
16 | if (_metadataClassType == null) {
17 | throw new InvalidOperationException(DataAnnotationsResources.MetadataTypeAttribute_TypeCannotBeNull);
18 | }
19 |
20 | return _metadataClassType;
21 | }
22 | }
23 |
24 | public MetadataTypeAttribute(Type metadataClassType) {
25 | _metadataClassType = metadataClassType;
26 | }
27 |
28 | }
29 | }
--------------------------------------------------------------------------------
/Portable.DataAnnotations.Net45Portable/ValidationAttributes/MinLengthAttribute.cs:
--------------------------------------------------------------------------------
1 | using System.ComponentModel.DataAnnotations.Resources;
2 | using System.Diagnostics.CodeAnalysis;
3 | using System.Globalization;
4 |
5 | namespace System.ComponentModel.DataAnnotations
6 | {
7 | ///
8 | /// Specifies the minimum length of array/string data allowed in a property.
9 | ///
10 | [AttributeUsage(AttributeTargets.Property | AttributeTargets.Field | AttributeTargets.Parameter, AllowMultiple = false)]
11 | [SuppressMessage("Microsoft.Performance", "CA1813:AvoidUnsealedAttributes", Justification = "We want users to be able to extend this class")]
12 | public class MinLengthAttribute : ValidationAttribute
13 | {
14 | ///
15 | /// Gets the minimum allowable length of the array/string data.
16 | ///
17 | public int Length { get; private set; }
18 |
19 | ///
20 | /// Initializes a new instance of the class.
21 | ///
22 | ///
23 | /// The minimum allowable length of array/string data.
24 | /// Value must be greater than or equal to zero.
25 | ///
26 | public MinLengthAttribute(int length)
27 | : base(DataAnnotationsResources.MinLengthAttribute_ValidationError)
28 | {
29 | Length = length;
30 | }
31 |
32 | protected override ValidationResult IsValid(object value, ValidationContext validationContext)
33 | {
34 | return base.IsValid(value, validationContext);
35 | }
36 |
37 | ///
38 | /// Determines whether a specified object is valid. (Overrides )
39 | ///
40 | ///
41 | /// This method returns true if the is null.
42 | /// It is assumed the is used if the value may not be null.
43 | ///
44 | /// The object to validate.
45 | /// true if the value is null or greater than or equal to the specified minimum length, otherwise false
46 | /// Length is less than zero.
47 | internal override bool IsValid(object value)
48 | {
49 | // Check the lengths for legality
50 | EnsureLegalLengths();
51 |
52 | var length = 0;
53 | // Automatically pass if value is null. RequiredAttribute should be used to assert a value is not null.
54 | if (value == null)
55 | {
56 | return true;
57 | }
58 | else
59 | {
60 | var str = value as string;
61 | if (str != null)
62 | {
63 | length = str.Length;
64 | }
65 | else
66 | {
67 | // We expect a cast exception if a non-{string|array} property was passed in.
68 | length = ((Array)value).Length;
69 | }
70 | }
71 |
72 | return length >= Length;
73 | }
74 |
75 | ///
76 | /// Applies formatting to a specified error message. (Overrides )
77 | ///
78 | /// The name to include in the formatted string.
79 | /// A localized string to describe the minimum acceptable length.
80 | public override string FormatErrorMessage(string name)
81 | {
82 | // An error occurred, so we know the value is less than the minimum
83 | return string.Format(CultureInfo.CurrentCulture, ErrorMessageString, name, Length);
84 | }
85 |
86 | ///
87 | /// Checks that Length has a legal value.
88 | ///
89 | /// Length is less than zero.
90 | private void EnsureLegalLengths()
91 | {
92 | if (Length < 0)
93 | {
94 | throw new InvalidOperationException(String.Format(CultureInfo.CurrentCulture, DataAnnotationsResources.MinLengthAttribute_InvalidMinLength));
95 | }
96 | }
97 | }
98 | }
--------------------------------------------------------------------------------
/Portable.DataAnnotations.Net45Portable/ValidationAttributes/PhoneAttribute.cs:
--------------------------------------------------------------------------------
1 | namespace System.ComponentModel.DataAnnotations
2 | {
3 | using System;
4 | using System.ComponentModel.DataAnnotations.Resources;
5 | using System.Text.RegularExpressions;
6 |
7 | [AttributeUsage(AttributeTargets.Property | AttributeTargets.Field | AttributeTargets.Parameter, AllowMultiple = false)]
8 | public sealed class PhoneAttribute : DataTypeAttribute
9 | {
10 | // see unit tests for examples
11 | private static Regex _regex = new Regex(@"^(\+\s?)?((? 0;
28 | }
29 | }
30 | }
--------------------------------------------------------------------------------
/Portable.DataAnnotations.Net45Portable/ValidationAttributes/RangeAttribute.cs:
--------------------------------------------------------------------------------
1 | using System.ComponentModel.DataAnnotations.Resources;
2 | using System.Diagnostics.CodeAnalysis;
3 | using System.Globalization;
4 |
5 | namespace System.ComponentModel.DataAnnotations
6 | {
7 | ///
8 | /// Used for specifying a range constraint
9 | ///
10 | [AttributeUsage(AttributeTargets.Property | AttributeTargets.Field | AttributeTargets.Parameter, AllowMultiple = false)]
11 | [SuppressMessage("Microsoft.Design", "CA1019:DefineAccessorsForAttributeArguments", Justification = "We want it to be accessible via method on parent.")]
12 | [SuppressMessage("Microsoft.Performance", "CA1813:AvoidUnsealedAttributes", Justification = "We want users to be able to extend this class")]
13 | public class RangeAttribute : ValidationAttribute
14 | {
15 | ///
16 | /// Gets the minimum value for the range
17 | ///
18 | public object Minimum { get; private set; }
19 |
20 | ///
21 | /// Gets the maximum value for the range
22 | ///
23 | public object Maximum { get; private set; }
24 |
25 | ///
26 | /// Gets the type of the and values (e.g. Int32, Double, or some custom type)
27 | ///
28 | public Type OperandType { get; private set; }
29 |
30 | private Func