public static string GetGenericInfos(object obj, string tabSpace = "") { var str = tabSpace + "{\n"; var types = obj.GetType(); var count = types.GetProperty("Count")?.GetValue(obj); var gens = (IEnumerable)obj; var index = 0; foreach (var variable in gens) { #region 可以优化的版本 // var protos = variable.GetType().GetProperty("Key"); // Debug.Log(protos); // if (protos !=null) // { // var key = protos.GetValue(variable); // // var values = variable.GetType().GetProperty("Value"); // // if (values!=null) // { // var fieldsStr = LogWin.GetObejctInfo(variable, tabSpace + " "); // } // } // else // { var fieldsStr = LogWin.GetObejctInfo(variable, tabSpace + " "); str += $"{tabSpace} [{index++}] = {fieldsStr},\n"; // } #endregion } var args = types.GetProperties(BindingFlags.Public | BindingFlags.Instance); str = str += tabSpace + "},\n"; return(str); }
private void Start() { var page = new Page { Title = "111", PageID = 123 }; var args = new Dictionary <int, string>() { [100] = "123", [200] = "2003" }; // var args = new Queue<int>() { }; // args.Enqueue(1); // args.Enqueue(3); // args.Enqueue(5); // Debug.Log(LogWin.GetObejctInfo(args)); // // var v3 = new Vector3(0,1,2); Debug.Log(args.GetType().IsGenericParameter); var gens = args.GetType() .GetProperties(BindingFlags.Instance | BindingFlags.Public | BindingFlags.GetField); // var fields = args.GetType().GetMembers(BindingFlags.Instance | BindingFlags.Public |BindingFlags.FlattenHierarchy); // Debug.Log(args.GetType().GetProperties()); // var pros = v3.GetType().GetProperties(BindingFlags.Instance | BindingFlags.Public); // Debug.Log(LogWin.GetObejctInfo(args)); // // // Debug.Log(LogWin.GetObejctInfo(v3)); }