QiFeng.ZWY.Utility/DataHelper/ConvertHelper.cs
(开头部分) 8KB这里只显示每个文件的开头 60 行。登录后可以解锁完整代码。
using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Reflection;
using System.Text;
using NPOI.SS.Formula.Functions;
namespace QiFeng.LMSD.Utility
{
public static class ConvertHelper
{
public static T GetFromReader<T>(IDataReader reader)
{
object result = Activator.CreateInstance(typeof(T));
for (int i = 0; i < reader.FieldCount; i++)
{
if (reader[i] == DBNull.Value)
continue;
PropertyInfo property = typeof(T).GetProperty(reader.GetName(i));//得到第i列的所有属性
if (property == null || !property.CanWrite)
continue;
if (property.PropertyType == typeof(bool))
property.SetValue(result, Convert.ToBoolean(reader[i]), null);
else
property.SetValue(result, reader[i], null);
}
return (T)result;
}
/// <summary>
/// Object转化为Decimal
/// </summary>
/// <param name="value"></param>
/// <returns></returns>
public static decimal ObjectToDecimal(object value)
{
return value == null || value == DBNull.Value ? 0 : Convert.ToDecimal(value);
}
/// <summary>
/// Object转化为Int32
/// </summary>
/// <param name="value"></param>
/// <returns></returns>
public static Int32 ObjectToInt32(object value)
{
return value == null || value == DBNull.Value ? 0 : Convert.ToInt32(value);
}
/// <summary>
/// Object转化为Int64
/// </summary>
/// <param name="value"></param>
/// <returns></returns>
public static Int64 ObjectToInt64(object value)
{
后面还有 190 行代码,解锁后查看完整代码
24 小时内免费解锁 3 个项目,之后 1 算力/个。 规则说明
AI 解读 AI
登录后可用,每次 10 算力,解读结果公开显示在下面。
还没有人解读过这个文件。