示例#1
0
        private static T LoadRecord <T>(DataRow row)
        {
            Type EntityType = typeof(T);
            T    newObject  = (T)Activator.CreateInstance(EntityType);

            foreach (DataColumn itme in row.Table.Columns)
            {
                var objValue = row[itme.ColumnName];
                if (objValue != null && objValue != DBNull.Value)
                {
                    /*lxt 20140925 原来的代码可能有问题,先让程序运行
                     * //var Property = EntityType.GetProperty(itme.ColumnName,BindingFlags.IgnoreCase );
                     * //PropertyInfo Property = SerializableData.GetObjPro(itme.ColumnName, EntityType);
                     * //if (Property != null)
                     * //{
                     * //    SetPropertyValue(newObject, Property, objValue);
                     * //}
                     * //else
                     * //{
                     * //    if (newObject is EntityBase)
                     * //    {
                     * //        (newObject as EntityBase)[itme.ColumnName] = objValue;
                     * //    }
                     * //}
                     */
                    if (EntityType == typeof(EntityBase))
                    {
                        (newObject as EntityBase)[itme.ColumnName] = objValue;
                    }
                    else
                    {
                        PropertyInfo Property = SerializableData.GetObjPro(itme.ColumnName, EntityType);
                        DataProvider.SetPropertyValue(newObject, Property, objValue);
                    }
                }
            }
            if (newObject is IEntity)
            {
                (newObject as IEntity).ResetStatus(EntityStatus.Original);
            }
            return(newObject);
        }