63 lines
1.2 KiB
C#
63 lines
1.2 KiB
C#
using System;
|
|
using Newtonsoft.Json.Linq;
|
|
|
|
namespace Hncore.Infrastructure.Extension
|
|
{
|
|
public static class NumberExtension
|
|
{
|
|
public static int ToInt(this int? num)
|
|
{
|
|
if (num == null)
|
|
{
|
|
return 0;
|
|
}
|
|
|
|
return Convert.ToInt32(num);
|
|
}
|
|
|
|
public static int ToInt(this JToken obj)
|
|
{
|
|
if (obj == null)
|
|
{
|
|
return 0;
|
|
}
|
|
|
|
int.TryParse(obj.ToString(), out var num);
|
|
|
|
return num;
|
|
}
|
|
|
|
public static decimal ToDecimal(this decimal? num)
|
|
{
|
|
if (num == null)
|
|
{
|
|
|
|
return 0;
|
|
}
|
|
|
|
return Convert.ToDecimal(num);
|
|
}
|
|
|
|
public static long ToLong(this long? num)
|
|
{
|
|
if (num == null)
|
|
{
|
|
return 0;
|
|
}
|
|
|
|
return (long) num;
|
|
}
|
|
|
|
public static int ToInt(this bool flag)
|
|
{
|
|
if (flag)
|
|
{
|
|
return 1;
|
|
}
|
|
else
|
|
{
|
|
return 0;
|
|
}
|
|
}
|
|
}
|
|
} |