public static ConfigInfo ConvertToConfigInfo(ConfigTemp model) { ConfigInfo configInfo = new ConfigInfo(); Type ToModel = configInfo.GetType(); Type FromModel = model.GetType(); var fileds = ToModel.GetProperties(); foreach (var item in fileds) { object fromValue = Convert.ChangeType(model.GetType().GetProperty(item.Name).GetValue(model, null), item.PropertyType); if (fromValue != null) { configInfo.GetType().GetProperty(item.Name).SetValue(configInfo, fromValue, null); } } return configInfo; }