/// <summary> /// 用json对象填充数据实体 /// </summary> /// <typeparam name="T"></typeparam> /// <param name="t"></param> /// <param name="jObj"></param> /// <param name="type"></param> /// <returns></returns> public static T JsonCopy <T>(this T t, JObject jObj, StringFormatEnum type) { var properties = typeof(T).GetProperties(); foreach (var propertie in properties) { if (jObj.ContainsKey(propertie.Name.FirstLetterToLow())) { if (propertie.PropertyType.IsValueType) { if (propertie.PropertyType == typeof(bool)) { propertie.SetValue(t, jObj[propertie.Name.FirstLetterToLow()].ToString().ToBool(), null); } else { propertie.SetValue(t, jObj[propertie.Name.FirstLetterToLow()].ToString().ToInt(), null); } } else if (propertie.PropertyType.Name.StartsWith("String")) { propertie.SetValue(t, jObj[propertie.Name.FirstLetterToLow()].ToString(), null); } else if (propertie.PropertyType.Name.StartsWith("String")) { propertie.SetValue(t, jObj[propertie.Name.FirstLetterToLow()].ToString(), null); } } } return(t); }
/// <summary> /// 字符串操作委托 /// </summary> /// <param name="type"></param> /// <returns></returns> public Func <string, string> StringFormat(StringFormatEnum type) { switch (type) { case StringFormatEnum.Up: return(str => { return str.ToLower(); }); default: return(str => { return str; }); } }
/// <summary> /// Standard Constructor. /// </summary> /// <param name="sfeOld">The old StringFormatEnum before the property was changed.</param> /// <param name="sfeNew">The new StringFormatEnum after the property was changed.</param> public StringFormatEnumEventArgs(StringFormatEnum sfeOld, StringFormatEnum sfeNew) { sfeOldStringFormatEnum = sfeOld; sfeNewStringFormatEnum = sfeNew; }