Fixed some perf concerns related to types conversion; Replaced tabs with spaces;

This commit is contained in:
ptsurbeleu 2012-02-10 00:01:39 -08:00
parent 4a16ca9524
commit 8b7b150da7

View file

@ -56,8 +56,18 @@ namespace WebsitePanel.Portal
public static DateTime ParseDate(string val) public static DateTime ParseDate(string val)
{ {
try { return DateTime.Parse(val); } // Perf: allow only non-empty strings to go through
catch { /* do nothing */ } if (!String.IsNullOrEmpty(val))
{
try
{
return DateTime.Parse(val);
}
catch
{
/* do nothing */
}
}
return DateTime.MinValue; return DateTime.MinValue;
} }
@ -69,24 +79,55 @@ namespace WebsitePanel.Portal
public static int ParseInt(object val, int defaultValue) public static int ParseInt(object val, int defaultValue)
{ {
int result = defaultValue; int result = defaultValue;
try { result = Int32.Parse(val.ToString()); } // Perf: allow only non-empty values to go through
catch { /* do nothing */ } if (val != null && val != String.Empty)
{
try
{
result = Int32.Parse(val.ToString());
}
catch
{
/* do nothing */
}
}
return result; return result;
} }
public static bool ParseBool(string val, bool defaultValue) public static bool ParseBool(string val, bool defaultValue)
{ {
bool result = defaultValue; bool result = defaultValue;
try { result = Boolean.Parse(val); } // Perf: allow only non-empty strings to go through
catch { /* do nothing */ } if (!String.IsNullOrEmpty(val))
{
try
{
result = Boolean.Parse(val);
}
catch
{
/* do nothing */
}
}
return result; return result;
} }
public static decimal ParseDecimal(string val, decimal defaultValue) public static decimal ParseDecimal(string val, decimal defaultValue)
{ {
decimal result = defaultValue; decimal result = defaultValue;
try { result = Decimal.Parse(val); } // Perf: allow only non-empty strings to go through
catch { /* do nothing */ } if (!String.IsNullOrEmpty(val))
{
try
{
result = Decimal.Parse(val);
}
catch
{
/* do nothing */
}
}
return result; return result;
} }