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

namespace Common
{
    public class EntityBase<T>
    {
        public M format<M>(T t, M m,List<string> list = null) 
        {
            PropertyInfo[] PropertyInfos1 = t.GetType().GetProperties();
            PropertyInfo[] PropertyInfos2 = m.GetType().GetProperties();

            object value;

            foreach (PropertyInfo p2 in PropertyInfos2) 
            {
                foreach (PropertyInfo p1 in PropertyInfos1) 
                {
                    if (list != null)
                    {
                        bool noChange = list.Contains(p2.Name);
                        if (noChange)
                        {
                            break;
                        }
                    }
                    if (p2.Name == "createManName" || p2.Name == "createManNo" || p2.Name == "createTime" || p2.Name == "updateManName" || p2.Name == "updateManNo" || p2.Name == "updateTime" || p2.Name == "valueFlag")
                    {
                        break;
                    }
                    if (p2.Name.ToUpper() == p1.Name.ToUpper()) 
                    {
                        value = p1.GetValue(t, null);
                        if (value != null)
                        {
                            p2.SetValue(m, value, null);
                        }
                    }
                }
            }
            return m;
        }
    }
}
