修改订单API下的Task 增加礼物的Task显示
修改转换器
This commit is contained in:
1 parent
9e71c54414
commit
b512ee992f
3 files changed
+340
-48
No files matched your search
@@ -1,13 +1,14 @@
|
||||
using System;
|
||||
using NaiBa.Util.Helper;
|
||||
using Newtonsoft.Json;
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.Globalization;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Runtime.Serialization.Formatters.Binary;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using NaiBa.Util.Helper;
|
||||
using Newtonsoft.Json;
|
||||
|
||||
namespace NaiBa.Util.Extension
|
||||
{
|
||||
@@ -102,22 +103,44 @@ namespace NaiBa.Util.Extension
|
||||
}
|
||||
}
|
||||
|
||||
public static int? ParseToNullableInt(this object str)
|
||||
{
|
||||
if (str == null)
|
||||
return null;
|
||||
public static int? ParseToNullableInt(this object str)
|
||||
{
|
||||
// 1. 快速判断:如果为 null 或 DBNull,直接返回
|
||||
if (str == null || str == DBNull.Value)
|
||||
return null;
|
||||
|
||||
try
|
||||
{
|
||||
return Convert.ToInt32(str);
|
||||
}
|
||||
catch
|
||||
{
|
||||
return null;
|
||||
}
|
||||
}
|
||||
// 2. 尝试直接转换类型(处理 int, short, long 等)
|
||||
if (str is int intVal)
|
||||
return intVal;
|
||||
if (str is long longVal && longVal >= int.MinValue && longVal <= int.MaxValue)
|
||||
return (int)longVal;
|
||||
|
||||
public static int DecimalPointParseToInt(this object str)
|
||||
// 3. 针对字符串进行处理(支持空格、空字符串)
|
||||
if (str is string strVal)
|
||||
{
|
||||
// 如果字符串为 null 或空白,视为 null
|
||||
if (string.IsNullOrWhiteSpace(strVal))
|
||||
return null;
|
||||
|
||||
if (int.TryParse(strVal, NumberStyles.Integer, CultureInfo.InvariantCulture, out int result))
|
||||
return result;
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
// 4. 其他类型(如 bool, DateTime)统一返回 null,保持严格
|
||||
try
|
||||
{
|
||||
return Convert.ToInt32(str);
|
||||
}
|
||||
catch
|
||||
{
|
||||
return null;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public static int DecimalPointParseToInt(this object str)
|
||||
{
|
||||
try
|
||||
{
|
||||
|
||||
Reference in new issue
Block a user