Ejemplo n.º 1
0
        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);
        }
Ejemplo n.º 2
0
        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));
        }
Ejemplo n.º 3
0
        /**
         *  打印日志
         */
        public static string GetObejctInfo(object obj, string tabSpace = "")
        {
            if (Utils.GetLogWinAsset().logMode == LogMode.PRODUCTION)
            {
                return($"{tabSpace}{obj.ToString()}");
            }

            var types = obj.GetType();
            var containsRelectionInfo = CheckUnityObject(obj);

            if (types.IsValueType && !types.IsEnum && !types.IsPrimitive)
            {
                return(LogWin.GetStructInfo(obj, tabSpace));
            }

            // Unity的东西
            if (containsRelectionInfo)
            {
                return(GetUnityObejctInfo(obj, tabSpace));
            }

            // 数组
            if (obj.GetType().IsArray)
            {
                return(GetObjectArrayInfo(obj, tabSpace));
            }



            // 泛型
            if (obj.GetType().IsGenericType)
            {
                Debug.Log("泛型");
                return(LogWin.GetGenericInfos(obj, tabSpace));
            }

            return($"{tabSpace}{obj.ToString()}");
        }
Ejemplo n.º 4
0
        public static string GetStructInfo(object obj, string tabSpace = "")
        {
            var containsRelectionInfo = CheckUnityObject(obj);

            //如果字段的长度是0  并且是
            if (LogWin.GetFieldsLength(obj) == 0 && containsRelectionInfo)
            {
                return("");
            }

            var str = tabSpace + "{\n";

            str += LogWin.GetFieldsLength(obj) == 0 ? "":FormatFieldInfo(obj, tabSpace + "  ");

            if (!containsRelectionInfo)
            {
                str += $"{ FormatPropertiesInfo(obj, tabSpace + "  ")}";
//                Debug.Log($"{}");
            }

            str += (tabSpace + "}\n");
            return(str);
        }