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