public static T SetModel<T>(this T model, SortedList<string, string> list) where T : Model { PropertyInfo[] propertyInfos = typeof(T).GetProperties(); foreach (var item in list) { if (propertyInfos.Count(x => string.Compare(x.Name, item.Key, true) == 0) == 1 && !string.IsNullOrEmpty(item.Value)) { propertyInfos.First(x => string.Compare(x.Name, item.Key, true) == 0).SetValue(model, item.Value, null); } } return model; }
swicth
你是指JS,还是后台?后台的话,可以用反射+循环搞定。对于js,验证50个字段,就更简单了。
List<T>.Contains();