当你的才华不能撑起你的野心时,就是你该选择学习的时候了!

C# Activator.CreateInstance

public Tout ConvertBase<Tout>(FCAQueryParameter fcaParameter) where Tout : QueryParameters
        {

            Tout postParameter = (Tout)Activator.CreateInstance(typeof(Tout));
            this.AutoMapping(fcaParameter, postParameter);return postParameter;
        }

 

        public void AutoMapping<S, T>(S s, T t)
        {
            PropertyInfo[] pps = s.GetType().GetProperties(BindingFlags.Public | BindingFlags.Instance);
            Type target = t.GetType();

            foreach (var pp in pps)
            {
                PropertyInfo targetPP = target.GetProperty(pp.Name);
                object value = pp.GetValue(s, null);

                if (targetPP != null && value != null && targetPP.CanWrite)
                {
                    targetPP.SetValue(t, value, null);
                }
            }
        }

 

posted @ 2021-09-23 09:49  hofmann  阅读(121)  评论(0编辑  收藏  举报