mirror of
https://gitee.com/dotnetchina/SqlSugar.git
synced 2025-11-08 02:14:53 +08:00
Update demo
This commit is contained in:
@@ -2,6 +2,8 @@
|
|||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using SqlSugar;
|
using SqlSugar;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
|
using SqlSugar.Extensions;
|
||||||
|
|
||||||
namespace OrmTest.UnitTest
|
namespace OrmTest.UnitTest
|
||||||
{
|
{
|
||||||
public class UnitTestBase
|
public class UnitTestBase
|
||||||
|
|||||||
@@ -253,6 +253,7 @@
|
|||||||
<Compile Include="Utilities\Check.cs" />
|
<Compile Include="Utilities\Check.cs" />
|
||||||
<Compile Include="Utilities\DbExtensions.cs" />
|
<Compile Include="Utilities\DbExtensions.cs" />
|
||||||
<Compile Include="Utilities\ErrorMessage.cs" />
|
<Compile Include="Utilities\ErrorMessage.cs" />
|
||||||
|
<Compile Include="Utilities\UtilExtensions.cs" />
|
||||||
<Compile Include="Utilities\UtilRandom.cs" />
|
<Compile Include="Utilities\UtilRandom.cs" />
|
||||||
<Compile Include="Utilities\ValidateExtensions.cs" />
|
<Compile Include="Utilities\ValidateExtensions.cs" />
|
||||||
<Compile Include="Utilities\UtilConstants.cs" />
|
<Compile Include="Utilities\UtilConstants.cs" />
|
||||||
|
|||||||
123
Src/Asp.Net/SqlSugar/Utilities/UtilExtensions.cs
Normal file
123
Src/Asp.Net/SqlSugar/Utilities/UtilExtensions.cs
Normal file
@@ -0,0 +1,123 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
namespace SqlSugar.Extensions
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
///Common Extensions for external users
|
||||||
|
/// </summary>
|
||||||
|
public static class UtilExtensions
|
||||||
|
{
|
||||||
|
public static int ObjToInt(this object thisValue)
|
||||||
|
{
|
||||||
|
int reval = 0;
|
||||||
|
if (thisValue == null) return 0;
|
||||||
|
if (thisValue is Enum)
|
||||||
|
{
|
||||||
|
return (int)thisValue;
|
||||||
|
}
|
||||||
|
if (thisValue != null && thisValue != DBNull.Value && int.TryParse(thisValue.ToString(), out reval))
|
||||||
|
{
|
||||||
|
return reval;
|
||||||
|
}
|
||||||
|
return reval;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static int ObjToInt(this object thisValue, int errorValue)
|
||||||
|
{
|
||||||
|
int reval = 0;
|
||||||
|
if (thisValue is Enum)
|
||||||
|
{
|
||||||
|
return (int)thisValue;
|
||||||
|
}
|
||||||
|
if (thisValue != null && thisValue != DBNull.Value && int.TryParse(thisValue.ToString(), out reval))
|
||||||
|
{
|
||||||
|
return reval;
|
||||||
|
}
|
||||||
|
return errorValue;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static double ObjToMoney(this object thisValue)
|
||||||
|
{
|
||||||
|
double reval = 0;
|
||||||
|
if (thisValue != null && thisValue != DBNull.Value && double.TryParse(thisValue.ToString(), out reval))
|
||||||
|
{
|
||||||
|
return reval;
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static double ObjToMoney(this object thisValue, double errorValue)
|
||||||
|
{
|
||||||
|
double reval = 0;
|
||||||
|
if (thisValue != null && thisValue != DBNull.Value && double.TryParse(thisValue.ToString(), out reval))
|
||||||
|
{
|
||||||
|
return reval;
|
||||||
|
}
|
||||||
|
return errorValue;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static string ObjToString(this object thisValue)
|
||||||
|
{
|
||||||
|
if (thisValue != null) return thisValue.ToString().Trim();
|
||||||
|
return "";
|
||||||
|
}
|
||||||
|
|
||||||
|
public static string ObjToString(this object thisValue, string errorValue)
|
||||||
|
{
|
||||||
|
if (thisValue != null) return thisValue.ToString().Trim();
|
||||||
|
return errorValue;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Decimal ObjToDecimal(this object thisValue)
|
||||||
|
{
|
||||||
|
Decimal reval = 0;
|
||||||
|
if (thisValue != null && thisValue != DBNull.Value && decimal.TryParse(thisValue.ToString(), out reval))
|
||||||
|
{
|
||||||
|
return reval;
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Decimal ObjToDecimal(this object thisValue, decimal errorValue)
|
||||||
|
{
|
||||||
|
Decimal reval = 0;
|
||||||
|
if (thisValue != null && thisValue != DBNull.Value && decimal.TryParse(thisValue.ToString(), out reval))
|
||||||
|
{
|
||||||
|
return reval;
|
||||||
|
}
|
||||||
|
return errorValue;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static DateTime ObjToDate(this object thisValue)
|
||||||
|
{
|
||||||
|
DateTime reval = DateTime.MinValue;
|
||||||
|
if (thisValue != null && thisValue != DBNull.Value && DateTime.TryParse(thisValue.ToString(), out reval))
|
||||||
|
{
|
||||||
|
reval = Convert.ToDateTime(thisValue);
|
||||||
|
}
|
||||||
|
return reval;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static DateTime ObjToDate(this object thisValue, DateTime errorValue)
|
||||||
|
{
|
||||||
|
DateTime reval = DateTime.MinValue;
|
||||||
|
if (thisValue != null && thisValue != DBNull.Value && DateTime.TryParse(thisValue.ToString(), out reval))
|
||||||
|
{
|
||||||
|
return reval;
|
||||||
|
}
|
||||||
|
return errorValue;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static bool ObjToBool(this object thisValue)
|
||||||
|
{
|
||||||
|
bool reval = false;
|
||||||
|
if (thisValue != null && thisValue != DBNull.Value && bool.TryParse(thisValue.ToString(), out reval))
|
||||||
|
{
|
||||||
|
return reval;
|
||||||
|
}
|
||||||
|
return reval;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user