2017-07-20 11:51:05 +08:00
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
using System.Text;
|
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
|
|
|
|
|
namespace UIInfoSuite.Extensions
|
|
|
|
|
{
|
|
|
|
|
static class StringExtensions
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public static Int32 SafeParseInt32(this String s)
|
|
|
|
|
{
|
|
|
|
|
Int32 result = 0;
|
|
|
|
|
|
|
|
|
|
if (!String.IsNullOrWhiteSpace(s))
|
|
|
|
|
{
|
|
|
|
|
Int32.TryParse(s, out result);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
|
2018-05-17 12:13:19 +08:00
|
|
|
|
public static Int64 SafeParseInt64(this String s)
|
|
|
|
|
{
|
|
|
|
|
Int64 result = 0;
|
|
|
|
|
|
|
|
|
|
if (!String.IsNullOrWhiteSpace(s))
|
|
|
|
|
Int64.TryParse(s, out result);
|
|
|
|
|
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
|
2017-07-20 11:51:05 +08:00
|
|
|
|
public static bool SafeParseBool(this String s)
|
|
|
|
|
{
|
|
|
|
|
bool result = false;
|
|
|
|
|
|
|
|
|
|
if (!String.IsNullOrWhiteSpace(s))
|
|
|
|
|
{
|
|
|
|
|
Boolean.TryParse(s, out result);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|