diff options
author | Ilya Kharmatsky <ilya@mono-cvs.ximian.com> | 2007-01-14 17:46:33 +0300 |
---|---|---|
committer | Ilya Kharmatsky <ilya@mono-cvs.ximian.com> | 2007-01-14 17:46:33 +0300 |
commit | 9c154b79485df79b61c72af2a888b05613f4af12 (patch) | |
tree | 87fab250bd37724be58a3067c33ebe52fa6193d1 /mcs/class/System.Web/System.Web.UI.WebControls/BaseCompareValidator.cs | |
parent | 76fa4e89210c5be0d996520976b5c47485054a82 (diff) |
Adding support for .net 2.0 property "BaseCompareValidator.CompareInvariantValues". The changes are also reflected in .net 1.1 implementations (the 2.0 related methods are defined
as 'internal' in this configuration)
svn path=/trunk/mcs/; revision=70983
Diffstat (limited to 'mcs/class/System.Web/System.Web.UI.WebControls/BaseCompareValidator.cs')
-rw-r--r-- | mcs/class/System.Web/System.Web.UI.WebControls/BaseCompareValidator.cs | 194 |
1 files changed, 119 insertions, 75 deletions
diff --git a/mcs/class/System.Web/System.Web.UI.WebControls/BaseCompareValidator.cs b/mcs/class/System.Web/System.Web.UI.WebControls/BaseCompareValidator.cs index 74fd4b5ee58..e85d9f21cf8 100644 --- a/mcs/class/System.Web/System.Web.UI.WebControls/BaseCompareValidator.cs +++ b/mcs/class/System.Web/System.Web.UI.WebControls/BaseCompareValidator.cs @@ -79,33 +79,7 @@ namespace System.Web.UI.WebControls { ValidationDataType type, out object value) { - try { - switch (type) { - case ValidationDataType.String: - value = text; - return value != null; - case ValidationDataType.Integer: - value = Int32.Parse (text); - return true; - case ValidationDataType.Double: - value = Double.Parse(text); - return true; - case ValidationDataType.Date: - value = DateTime.Parse(text); - return true; - case ValidationDataType.Currency: - value = Decimal.Parse(text, NumberStyles.Currency); - return true; - default: - value = null; - return false; - } - } - catch { - value = null; - return false; - } - + return BaseCompareValidator.Convert(text, type, false, out value); } protected static bool Compare (string left, @@ -113,40 +87,7 @@ namespace System.Web.UI.WebControls { ValidationCompareOperator op, ValidationDataType type) { - object lo, ro; - - if (!Convert (left, type, out lo)) - return false; - - /* DataTypeCheck is a unary operator that only - * depends on the lhs */ - if (op == ValidationCompareOperator.DataTypeCheck) - return true; - - /* pretty crackladen, but if we're unable to - * convert the rhs to @type, the comparison - * succeeds */ - if (!Convert (right, type, out ro)) - return true; - - int comp = ((IComparable)lo).CompareTo ((IComparable)ro); - - switch (op) { - case ValidationCompareOperator.Equal: - return comp == 0; - case ValidationCompareOperator.NotEqual: - return comp != 0; - case ValidationCompareOperator.LessThan: - return comp < 0; - case ValidationCompareOperator.LessThanEqual: - return comp <= 0; - case ValidationCompareOperator.GreaterThan: - return comp > 0; - case ValidationCompareOperator.GreaterThanEqual: - return comp >= 0; - default: - return false; - } + return BaseCompareValidator.Compare(left, false, right, false, op, type); } protected override bool DetermineRenderUplevel () @@ -220,18 +161,24 @@ namespace System.Web.UI.WebControls { #if NET_2_0 [DefaultValue (false)] [Themeable (false)] - public bool CultureInvariantValues { + public +#else + internal +#endif + bool CultureInvariantValues { get { return ViewState.GetBool ("CultureInvariantValues", false); } set { ViewState ["CultureInvariantValues"] = value; } } -#endif - protected static int CutoffYear { + + + protected static int CutoffYear { get { return CultureInfo.CurrentCulture.Calendar.TwoDigitYearMax; } } + [DefaultValue(ValidationDataType.String)] #if NET_2_0 [Themeable (false)] @@ -244,36 +191,133 @@ namespace System.Web.UI.WebControls { } #if NET_2_0 - [MonoTODO ("Not implemented")] - public static bool CanConvert (string text, + + public +#else + internal +#endif + static bool CanConvert (string text, ValidationDataType type, bool cultureInvariant) { - throw new NotImplementedException (); + object value; + return Convert(text, type, cultureInvariant, out value); } - [MonoTODO ("Not implemented")] - protected static bool Compare (string leftText, +#if NET_2_0 + protected +#else + internal +#endif + static bool Compare (string left, bool cultureInvariantLeftText, - string rightText, + string right, bool cultureInvariantRightText, ValidationCompareOperator op, ValidationDataType type) { - throw new NotImplementedException (); + object lo, ro; + + if (!Convert(left, type, cultureInvariantLeftText, out lo)) + return false; + + /* DataTypeCheck is a unary operator that only + * depends on the lhs */ + if (op == ValidationCompareOperator.DataTypeCheck) + return true; + + /* pretty crackladen, but if we're unable to + * convert the rhs to @type, the comparison + * succeeds */ + if (!Convert(right, type, cultureInvariantRightText, out ro)) + return true; + + int comp = ((IComparable)lo).CompareTo((IComparable)ro); + + switch (op) + { + case ValidationCompareOperator.Equal: + return comp == 0; + case ValidationCompareOperator.NotEqual: + return comp != 0; + case ValidationCompareOperator.LessThan: + return comp < 0; + case ValidationCompareOperator.LessThanEqual: + return comp <= 0; + case ValidationCompareOperator.GreaterThan: + return comp > 0; + case ValidationCompareOperator.GreaterThanEqual: + return comp >= 0; + default: + return false; + } } - [MonoTODO ("Not implemented")] - protected static bool Convert (string text, +#if NET_2_0 + protected +#else + internal +#endif + static bool Convert (string text, ValidationDataType type, bool cultureInvariant, out object value) { - throw new NotImplementedException (); + try + { + switch (type) + { + case ValidationDataType.String: + value = text; + return value != null; + + case ValidationDataType.Integer: + IFormatProvider intFormatProvider = (cultureInvariant) ? + NumberFormatInfo.InvariantInfo : + NumberFormatInfo.CurrentInfo; + value = Int32.Parse(text, intFormatProvider); + return true; + + case ValidationDataType.Double: + IFormatProvider doubleFormatProvider = (cultureInvariant) ? + NumberFormatInfo.InvariantInfo : + NumberFormatInfo.CurrentInfo; + value = Double.Parse(text, doubleFormatProvider); + return true; + + case ValidationDataType.Date: + + IFormatProvider dateFormatProvider = (cultureInvariant) ? + DateTimeFormatInfo.InvariantInfo : + DateTimeFormatInfo.CurrentInfo; + + value = DateTime.Parse(text, dateFormatProvider); + return true; + + case ValidationDataType.Currency: + IFormatProvider currencyFormatProvider = (cultureInvariant) ? + NumberFormatInfo.InvariantInfo : + NumberFormatInfo.CurrentInfo; + value = Decimal.Parse(text, NumberStyles.Currency, currencyFormatProvider); + return true; + + default: + value = null; + return false; + } + } + catch + { + value = null; + return false; + } } -#endif } } + + + + |