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);
                }
            }
        }
原文地址:https://www.cnblogs.com/hofmann/p/15322864.html