📄 basecomparevalidator.cs
字号:
using System;
using System.Globalization;
namespace System.Web.UI.WebControls
{
/// <summary>
/// Summary description for BaseCompareValidator.
/// </summary>
public abstract class BaseCompareValidator : BaseValidator
{
protected BaseCompareValidator() : base()
{
}
protected override void AddAttributesToRender(System.Web.UI.HtmlTextWriter writer)
{
ValidationDataType local0;
NumberFormatInfo local1;
string local2;
string local3;
string local4;
int local5;
int local6;
int local7;
int local8;
DateTime local9;
this.AddAttributesToRender(writer);
if (this.RenderUplevel)
{
local0 = this.Type;
if (local0 != ValidationDataType.String)
{
writer.AddAttribute("type", System.Web.UI.PropertyConverter.EnumToString(typeof(ValidationDataType), local0));
local1 = NumberFormatInfo.CurrentInfo;
if (local0 == ValidationDataType.Double)
{
local2 = NumberFormatInfo.CurrentInfo.NumberDecimalSeparator;
writer.AddAttribute("decimalchar", local2);
return;
}
if (local0 == ValidationDataType.Currency)
{
local3 = local1.CurrencyDecimalSeparator;
writer.AddAttribute("decimalchar", local3);
local4 = local1.CurrencyGroupSeparator;
if (local4[0] == 160)
local4 = " ";
writer.AddAttribute("groupchar", local4);
local5 = local1.CurrencyDecimalDigits;
writer.AddAttribute("digits", local5.ToString(NumberFormatInfo.InvariantInfo));
return;
}
if (local0 == ValidationDataType.Date)
{
writer.AddAttribute("dateorder", BaseCompareValidator.GetDateElementOrder());
local8 = BaseCompareValidator.CutoffYear;
writer.AddAttribute("cutoffyear", local8.ToString());
local9 = DateTime.Today;
local6 = local9.Year;
local7 = local6 - local6 % 100;
writer.AddAttribute("century", local7.ToString());
}
}
}
}
public static bool CanConvert(string text, ValidationDataType type)
{
object local0;
local0 = null;
return BaseCompareValidator.Convert(text, type, out local0);
}
//Comment:TMD,这个方法太长了
protected static bool Convert(string text, ValidationDataType type, out object value)
{
string V_0;
string V_1;
System.Text.RegularExpressions.Match V_2;
string V_3;
string V_4;
string V_5;
System.Text.RegularExpressions.Match V_6;
int V_7;
int V_8;
int V_9;
string V_10;
System.DateTime V_11;
System.Globalization.NumberFormatInfo V_12;
string V_13;
string V_14;
int V_15;
string V_16;
System.Text.RegularExpressions.Match V_17;
System.Text.StringBuilder V_18;
System.Text.RegularExpressions.Capture V_19;
ValidationDataType V_20;
string[] V_21;
string[] V_22;
System.Collections.IEnumerator V_23;
System.IDisposable V_24;
value = null;
try
{
V_20 = type;
switch(V_20)
{
case ValidationDataType.String:
value = text;
break;
case ValidationDataType.Integer:
value = int.Parse(text, System.Globalization.CultureInfo.InvariantCulture);
break;
case ValidationDataType.Double:
V_0 = System.Globalization.NumberFormatInfo.CurrentInfo.NumberDecimalSeparator;
V_1 = string.Concat(
@"^\\s*([-\\+])\?(\\d+)\?(\\",
V_0,
@"(\\d+))\?\\s*$"
);
V_2 = System.Text.RegularExpressions.Regex.Match(text, V_1);
//line 0069
if(V_2.Success) //else goto 04df
{
}
V_3 = string.Concat(
V_2.Groups[1].Value,
(V_2.Groups[2].Success) ? V_2.Groups[2].Value : "0",
string.Concat(
"", //line
V_2.Groups[4].Value // line 00cf
)
);
//TODO:
value = double.Parse(V_3, System.Globalization.CultureInfo.InvariantCulture);
break; //goto 004f
if(DateTimeFormatInfo.CurrentInfo.Calendar.GetType() != typeof(GregorianCalendar))
{
value = DateTime.Parse(text);
break;
}
V_4 = BaseCompareValidator.GetDateElementOrder();
V_5 = @"^\\s*((\\d{4})|(\\d{2}))([-./])(\\d{1,2})\\4(\\d{1,2})\\s*$";
V_6 = System.Text.RegularExpressions.Regex.Match(text, V_5);
//line 0147
if(V_6.Success) //else goto 0213
{
if((V_6.Groups[2].Success)
|| (V_4 == "ymd") //else goto 0213
)
{
V_7 = int.Parse(
V_6.Groups[6].Value,
System.Globalization.CultureInfo.InvariantCulture
);
//line 0196
V_8 = int.Parse(
V_6.Groups[5].Value,
System.Globalization.CultureInfo.InvariantCulture
);
//line 01b4
if(V_6.Groups[2].Success)
{
V_9 = int.Parse(
V_6.Groups[2].Value,
System.Globalization.CultureInfo.InvariantCulture
);
} //goto 0320
else
{
//line 01eb
if(V_6.Groups[3].Success)
{
V_9 = int.Parse(
V_6.Groups[2].Value,
System.Globalization.CultureInfo.InvariantCulture
);
} //goto 0320
}
}
}
else
{
//line 0213
if(V_4 != "ymd") //else goto 028d
{
V_10 = "^\\s*(\\d{1,2})([-./])(\\d{1,2})\\2((\\d{4})|(\\d{2}))\\s*$";
//line 022b
V_6 = System.Text.RegularExpressions.Regex.Match(text, V_10);
if(V_6.Success) //else goto 04df
{
V_7 = int.Parse(
V_6.Groups[3].Value,
System.Globalization.CultureInfo.InvariantCulture
);
//line 026d
V_8 = int.Parse(
V_6.Groups[1].Value,
System.Globalization.CultureInfo.InvariantCulture
);
//goto 02c9
}
}
else
{
//line 028d
V_7 = int.Parse(
V_6.Groups[1].Value,
System.Globalization.CultureInfo.InvariantCulture
);
V_8 = int.Parse(
V_6.Groups[3].Value,
System.Globalization.CultureInfo.InvariantCulture
);
}
//line 02c9
if(V_6.Groups[5].Success) //else goto 02fd
{
V_9 = int.Parse(
V_6.Groups[5].Value,
System.Globalization.CultureInfo.InvariantCulture
);
//goto 0320
}
else // line 02fd
{
V_9 = int.Parse(
V_6.Groups[6].Value,
System.Globalization.CultureInfo.InvariantCulture
);
}
}
//line 0320
V_11 = new System.DateTime(V_9, V_8, V_7);
//line 032d
if(V_11 == DateTime.MinValue)
{
value = V_11;
}
break; //goto 04df
case ValidationDataType.Currency:
V_12 = System.Globalization.NumberFormatInfo.CurrentInfo;
V_13 = V_12.CurrencyDecimalSeparator;
V_14 = V_12.CurrencyGroupSeparator;
if(V_14[0] == 160)
{
V_14 = " ";
}
V_15 = V_12.CurrencyDecimalDigits;
V_21 = new string[5];
V_21[0] = @"^\\s*([-\\+])\?(((\\d+)\\";
V_21[1] = V_14;
V_21[2] = ")*)(\\d+)"; //line 039d
//V_21[3] = V_15;
break;
}
//foreach(
}
catch
{
value = null;
}
//line 04e7
return value != null;
}
protected static bool Compare(string leftText, string rightText, ValidationCompareOperator op, ValidationDataType type)
{
object local0;
object local1;
int local2;
ValidationDataType local3;
int local4;
double local5;
DateTime local6;
Decimal local7;
ValidationCompareOperator local8;
if (!(BaseCompareValidator.Convert(leftText, type, out local0)))
return false;
if (op == ValidationCompareOperator.DataTypeCheck)
return true;
if (!(BaseCompareValidator.Convert(rightText, type, out local1)))
return true;
local3 = type;
switch (local3)
{
case ValidationDataType.String:
local2 = ((string)local0).CompareTo(local1);
break;
case ValidationDataType.Integer:
local4 = (int) local0;
local2 = local4.CompareTo(local1);
break;
case ValidationDataType.Double:
local5 = (double) local0;
local2 = local5.CompareTo(local1);
break;
case ValidationDataType.Date:
local6 = (DateTime) local0;
local2 = local6.CompareTo(local1);
break;
case ValidationDataType.Currency:
local7 = (decimal) local0;
local2 = local7.CompareTo(local1);
break;
default:
return true;
}
local8 = op;
switch (local8)
{
case ValidationCompareOperator.Equal:
return local2 == 0;
case ValidationCompareOperator.NotEqual:
return local2 != 0;
case ValidationCompareOperator.GreaterThan:
return local2 > 0;
case ValidationCompareOperator.GreaterThanEqual:
return local2 >= 0;
case ValidationCompareOperator.LessThan:
return local2 < 0;
case ValidationCompareOperator.LessThanEqual:
return local2 <= 0;
}
return true;
}
protected override bool DetermineRenderUplevel()
{
if((this.Type == ValidationDataType.Date)
&& (DateTimeFormatInfo.CurrentInfo.Calendar.GetType() != typeof(GregorianCalendar))
)
{
return false;
}
return this.DetermineRenderUplevel();
}
protected static string GetDateElementOrder()
{
throw new Exception("TODO");
DateTimeFormatInfo local0;
string local1;
local0 = DateTimeFormatInfo.CurrentInfo;
local1 = local0.ShortDatePattern;
if (local1.IndexOf('y') < local1.IndexOf('M'))
return "ymd";
if (local1.IndexOf('M') < local1.IndexOf('d'))
return "mdy";
return "dmy";
}
protected static int GetFullYear(int shortYear)
{
int local0;
int local1;
DateTime local2;
local2 = DateTime.Today;
local0 = local2.Year;
local1 = local0 - local0 % 100;
if (shortYear < BaseCompareValidator.CutoffYear)
return shortYear + local1;
return shortYear + local1 - 100;
}
protected static int CutoffYear
{
get
{
return DateTimeFormatInfo.CurrentInfo.Calendar.TwoDigitYearMax;
}
}
public ValidationDataType Type
{
get
{
object local0;
local0 = this.ViewState["Type"];
if (local0 != null)
return (ValidationDataType) local0;
return ValidationDataType.String;
}
set
{
if ((int)value < 0 || (int)value > 4)
throw new ArgumentOutOfRangeException("value");
this.ViewState["Type"] = value;
}
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -