Fixed some perf concerns related to types conversion; Replaced tabs with spaces;
This commit is contained in:
parent
4a16ca9524
commit
8b7b150da7
1 changed files with 84 additions and 43 deletions
|
@ -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;
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue