Admin.Core/src/platform/ZhonTai.Common/Extensions/UtilConvertExtension.cs
(开头部分) 5KB这里只显示每个文件的开头 60 行。登录后可以解锁完整代码。
using System;
using System.Text;
namespace ZhonTai.Common.Extensions;
/// <summary>
/// 数据类型转换
/// </summary>
public static class UtilConvertExtension
{
public static int ToInt(this object s, bool round = false)
{
if (s == null || s == DBNull.Value)
return 0;
if (s is bool b)
return b ? 1 : 0;
if (int.TryParse(s.ToString(), out int result))
return result;
if (s.GetType().IsEnum)
{
return (int)s;
}
var f = s.ToFloat();
return round ? Convert.ToInt32(f) : (int)f;
}
public static long ToLong(this object s)
{
if (s == null || s == DBNull.Value)
return 0L;
long.TryParse(s.ToString(), out long result);
return result;
}
public static double ToMoney(this object thisValue)
{
double reval;
if (thisValue != null && thisValue != DBNull.Value && double.TryParse(thisValue.ToString(), out reval))
{
return reval;
}
return 0;
}
public static double ToMoney(this object thisValue, double errorValue)
{
double reval;
if (thisValue != null && thisValue != DBNull.Value && double.TryParse(thisValue.ToString(), out reval))
{
return reval;
}
return errorValue;
}
public static string ToString(this object thisValue)
后面还有 159 行代码,解锁后查看完整代码
24 小时内免费解锁 3 个项目,之后 1 积分/个。 规则说明
AI 解读
登录后可用,每次 10 积分,解读结果公开显示在下面。
还没有人解读过这个文件。
