Sry.Framework.Dal/DataRowMapping.cs

(开头部分) 3KB

这里只显示每个文件的开头 60 行。登录后可以解锁完整代码。

using System;
using System.Collections.Generic;
using System.Data;
using System.Data.SqlClient;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Threading.Tasks;

namespace Sry.Framework.Dal
{

    public class DataRowMapping
    {
        /// <summary>
        /// 填充对象
        /// </summary>
        /// <param name="dr"></param>
        /// <param name="entity"></param>
        public static TResult ReceiveEntity<TResult>(DataRow dr)
        {
            if (dr==null)
                return default(TResult);
            var type = typeof(TResult);
            TResult baseEntity = (TResult)Activator.CreateInstance(type);
            foreach (PropertyInfo propertyInfo in type.GetProperties())
            {
                try
                {
                    if (dr.Table.Columns.Contains(propertyInfo.Name))
                        baseEntity.GetType().GetProperty(propertyInfo.Name).SetValue(baseEntity, dr[propertyInfo.Name], null);

                }
                catch { }
            }

            return baseEntity;
        }
        /// <summary>
        /// 填充对象列表
        /// </summary>
        /// <param name="ds"></param>
        /// <param name="entity"></param>
        /// <returns></returns>
        public static List<T> ReceiveEntity<T>(DataSet ds)
        {
            if (!(ds != null && ds.Tables.Count > 0))
                return null;

            List<T> entityList = new List<T>();
            foreach (DataRow dr in ds.Tables[0].Rows)
            {
                var baseEntity = ReceiveEntity<T>(dr);
                entityList.Add(baseEntity);
            }

            return entityList;
        }
        static bool readerExists(SqlDataReader dr, string columnName)
        {
后面还有 71 行代码,购买后查看完整代码

24 小时内免费解锁 3 个项目,之后 1 算力/个。 规则说明

AI 解读 AI

登录后可用,每次 10 算力,解读结果公开显示在下面。

还没有人解读过这个文件。