• c# class copy class


    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Web;
    using System.Web.Services;
    using System.Collections;
    using System.Text;
    using ChoosesClass.Data;
    using ChoosesClass.Entities;
    using ChoosesClass.Data.SqlClient;
    using System.Reflection;

    /// <summary>
    ///  WSTableToTable 的摘要说明
    ///
    /// TableClass tableClass = DataRepository.BoxProvider.GetByFBoxId(1);
    /// TableClass2 tableClass2 = new BoxServer();        
    /// CopyClass(tableClass2, tableClass);
    /// tableClass2=(tableClass2) CopyClass(tableClass2, tableClass);
    /// </summary>
    public class TableClassToTableClass
    {
        /// <summary>
        /// 拷贝类的方法
        /// </summary>
        /// <param name="class1">要拷贝的类</param>
        /// <param name="class2">被拷贝的类(只能是orm的表生成的类)</param>
         // public static object CopyTableClass(object tableClass, object tableClass2)
        public static void CopyTableClass(object tableClass, object tableClass2)
        {
            //得到class的类型
            Type typeTableClass = tableClass.GetType();
            Type typeTableClass2 = tableClass2.GetType();
            //得到class2的基元类型
            PropertyInfo cloumn = typeTableClass2.GetProperty("TableColumns");
            //得到所有的字段名称
            string[] list = (string[])cloumn.GetValue(tableClass2, null);
            foreach (object item in list)
            {

                PropertyInfo proTableClass = typeTableClass.GetProperty(item.ToString());
                PropertyInfo proTableClass2 = typeTableClass2.GetProperty(item.ToString());
                //给class1的每个字段赋值
                proTableClass.SetValue(tableClass, proTableClass2.GetValue(tableClass2, null), null);
            }
            //return tableClass;
        }
        //    TableClass tableClass = DataRepository.BoxProvider.GetByFBoxId(1);
        //    TableClass2 tableClass2 = new BoxServer();        
        //    CopyClass(tableClass2, tableClass);           
        //    tableClass2=(tableClass2) CopyClass(tableClass2, tableClass);

      
       
        //TList<table> tListBox = DataRepository.BoxProvider.GetAll();


        //    List<BoxServer> listBoxServer = new List<BoxServer>();

        //    Array list = Enum.GetValues(typeof(BoxColumn));

        //    foreach (Box item in tListBox)
        //    {
        //        BoxServer boxServer = new BoxServer();
        //        foreach (BoxColumn item1 in list)
        //        {
        //            Type typeBox = item.GetType();
        //            Type typeBoxServer = boxServer.GetType();

        //            PropertyInfo probox = typeBox.GetProperty(item1.ToString());
        //            PropertyInfo proboxServer = typeBoxServer.GetProperty(item1.ToString());

        //            proboxServer.SetValue(boxServer, probox.GetValue(item, null), null);
        //        }
        //        listBoxServer.Add(boxServer);
        //    }
       
    }

  • 相关阅读:
    Zabbix5 Frame 嵌套
    Zabbix5 对接 SAML 协议 SSO
    CentOS7 安装 Nexus
    CentOS7 安装 SonarQube
    GitLab 后台修改用户密码
    GitLab 查看版本号
    GitLab Admin Area 500 Error
    Linux 安装 PostgreSQL
    Liger ui grid 参数
    vue.js 是一个怪东西
  • 原文地址:https://www.cnblogs.com/xsmhero/p/xsm.html
Copyright © 2020-2023  润新知