diff options
author | Marek Safar <marek.safar@gmail.com> | 2014-05-15 21:43:25 +0400 |
---|---|---|
committer | Marek Safar <marek.safar@gmail.com> | 2014-05-15 21:44:20 +0400 |
commit | 563a83943ed26fcfbdd4cf95dbb6b4a3d52e0a76 (patch) | |
tree | ca3025e5515fa131d8a8407529c3f60d72c1a174 /mcs/class/System.ComponentModel.DataAnnotations | |
parent | 509ce4486facc0aa59928b34ff935503631536f5 (diff) |
[System.ComponentModel.DataAnnotations] Add UrlAttribute type.
Diffstat (limited to 'mcs/class/System.ComponentModel.DataAnnotations')
2 files changed, 53 insertions, 0 deletions
diff --git a/mcs/class/System.ComponentModel.DataAnnotations/System.ComponentModel.DataAnnotations.dll.sources b/mcs/class/System.ComponentModel.DataAnnotations/System.ComponentModel.DataAnnotations.dll.sources index 149117bda03..7fdb746ad04 100644 --- a/mcs/class/System.ComponentModel.DataAnnotations/System.ComponentModel.DataAnnotations.dll.sources +++ b/mcs/class/System.ComponentModel.DataAnnotations/System.ComponentModel.DataAnnotations.dll.sources @@ -25,5 +25,6 @@ System.ComponentModel.DataAnnotations/ScaffoldColumnAttribute.cs System.ComponentModel.DataAnnotations/ScaffoldTableAttribute.cs System.ComponentModel.DataAnnotations/StringLengthAttribute.cs System.ComponentModel.DataAnnotations/UIHintAttribute.cs +System.ComponentModel.DataAnnotations/UrlAttribute.cs System.ComponentModel.DataAnnotations/ValidationAttribute.cs System.ComponentModel.DataAnnotations/ValidationException.cs diff --git a/mcs/class/System.ComponentModel.DataAnnotations/System.ComponentModel.DataAnnotations/UrlAttribute.cs b/mcs/class/System.ComponentModel.DataAnnotations/System.ComponentModel.DataAnnotations/UrlAttribute.cs new file mode 100644 index 00000000000..4fa0dec8218 --- /dev/null +++ b/mcs/class/System.ComponentModel.DataAnnotations/System.ComponentModel.DataAnnotations/UrlAttribute.cs @@ -0,0 +1,52 @@ +// +// UrlAttribute.cs +// +// Authors: +// Marek Safar <marek.safar@gmail.com> +// +// Copyright (C) 2014 Xamarin Inc (http://www.xamarin.com) +// +// Permission is hereby granted, free of charge, to any person obtaining +// a copy of this software and associated documentation files (the +// "Software"), to deal in the Software without restriction, including +// without limitation the rights to use, copy, modify, merge, publish, +// distribute, sublicense, and/or sell copies of the Software, and to +// permit persons to whom the Software is furnished to do so, subject to +// the following conditions: +// +// The above copyright notice and this permission notice shall be +// included in all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE +// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION +// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +// + +#if NET_4_5 + +namespace System.ComponentModel.DataAnnotations +{ + [AttributeUsageAttribute (AttributeTargets.Property | AttributeTargets.Field | AttributeTargets.Parameter, AllowMultiple = false)] + public sealed class UrlAttribute : DataTypeAttribute + { + public UrlAttribute () + : base (DataType.Url) + { + } + + public override bool IsValid (object value) + { + if (value == null) + return true; + + var s = value as string; + return s != null && Uri.IsWellFormedUriString (s, UriKind.Absolute); + } + } +} + +#endif
\ No newline at end of file |