在线时间:8:00-16:00
迪恩网络APP
随时随地掌握行业动态
扫描二维码
关注迪恩网络微信公众号
public static class ToObject<T> where T : class { public static Dictionary<string, string> values = new Dictionary<string, string>(); static object target; private static void CreateInitiate() { Type t = typeof(T); ConstructorInfo ct = t.GetConstructor(System.Type.EmptyTypes); target = (T)ct.Invoke(null); } public static T ToEgg() { if (target != null) { target = null; } CreateInitiate(); Type t = target.GetType(); FieldInfo[] fields = t.GetFields(); string fieldName = string.Empty; values.Add("id", "200"); values.Add("path", "Model/Image"); foreach (FieldInfo f in fields) { fieldName = f.Name; Debug.Log(fieldName); f.SetValue(target, Convert.ChangeType(values[fieldName], f.FieldType)); } return (T)target; } } 这样就可以经过修改,把Json字符串或者xml字符串转化为类了 |
2023-10-27
2022-08-15
2022-08-17
2022-09-23
2022-08-13
请发表评论