src/YL.Utils/Extensions/TypeExt.cs
(开头部分) 3KB这里只显示每个文件的开头 60 行。登录后可以解锁完整代码。
using System;
using System.ComponentModel;
using System.Globalization;
using YL.Utils.Check;
namespace YL.Utils.Extensions
{
/// <summary>
/// 类型转换
/// </summary>
public static class TypeExt
{
public static int ToInt32(this object obj)
{
return int.TryParse(obj.ToString(), out int a) == true ? a : 0;
}
public static int ToInt32(this Enum obj)
{
return Convert.ToInt32(obj);
}
public static string EnumToString(this Enum obj)
{
return Convert.ToString(obj);
}
public static byte ToByte(this Enum obj)
{
return Convert.ToByte(obj);
}
public static byte ToByte(this object obj)
{
return byte.TryParse(obj.ToString(), out byte a) == true ? a : (byte)0;
}
public static long ToInt64(this object obj)
{
return long.TryParse(obj.ToString(), out long a) == true ? a : 0;
}
public static float ToFloat(this object obj)
{
return float.TryParse(obj.ToString(), out float a) == true ? a : 0;
}
public static decimal ToDecimal(this object obj)
{
return decimal.TryParse(obj.ToString(), out decimal a) == true ? a : 0;
}
public static double ToDouble(this object obj)
{
return double.TryParse(obj.ToString(), out double a) == true ? a : 0;
}
public static T To2<T>(this object obj)
where T : struct
{
后面还有 89 行代码,解锁后查看完整代码
24 小时内免费解锁 3 个项目,之后 1 算力/个。 规则说明
AI 解读 AI
登录后可用,每次 10 算力,解读结果公开显示在下面。
还没有人解读过这个文件。