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)
|
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;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue