예제 #1
0
        public static void PrintObjectInnerString(Type t, object obj, string instance_base_name)
        {
            DebugVars v = GetVarsFromClass(t, instance_base_name, obj);

            string str = v.ToString();

            Console.WriteLine(str);
        }
예제 #2
0
        public static void WriteObject(Type t, object obj, string instance_base_name)
        {
            if (Dbg.IsDebugMode == false)
            {
                return;
            }

            DebugVars v = GetVarsFromClass(t, instance_base_name, obj);

            string str = v.ToString();

            Console.WriteLine(str);
        }
예제 #3
0
        public static DebugVars GetVarsFromClass(Type t, string name = null, object obj = null, ImmutableHashSet <object> duplicate_check = null)
        {
            if (duplicate_check == null)
            {
                duplicate_check = ImmutableHashSet <object> .Empty;
            }

            if (Str.IsEmptyStr(name))
            {
                name = t.Name;
            }

            DebugVars ret = new DebugVars();

            var members_list = GetAllMembersFromType(t, obj != null, obj == null);

            foreach (MemberInfo info in members_list)
            {
                bool ok = false;
                if (info.MemberType == MemberTypes.Field)
                {
                    FieldInfo fi = info as FieldInfo;

                    ok = true;

                    if (fi.IsInitOnly)
                    {
                        ok = false;
                    }
                }
                else if (info.MemberType == MemberTypes.Property)
                {
                    PropertyInfo pi = info as PropertyInfo;

                    ok = true;
                }

                if (ok)
                {
                    //if (info.Name == "lockFile") Debugger.Break();

                    object data      = GetValueOfFieldOrProperty(info, obj);
                    Type   data_type = data?.GetType() ?? null;

                    if (IsPrimitiveType(data_type))
                    {
                        ret.Vars.Add((info, data));
                    }
                    else
                    {
                        if (data == null)
                        {
                            ret.Vars.Add((info, null));
                        }
                        else
                        {
                            if (data is IEnumerable)
                            {
                                int n = 0;
                                foreach (object item in (IEnumerable)data)
                                {
                                    if (duplicate_check.Contains(item) == false)
                                    {
                                        Type data_type2 = item?.GetType() ?? null;

                                        if (IsPrimitiveType(data_type2))
                                        {
                                            ret.Vars.Add((info, item));
                                        }
                                        else if (item == null)
                                        {
                                            ret.Vars.Add((info, null));
                                        }
                                        else
                                        {
                                            ret.Childlen.Add(GetVarsFromClass(data_type2, info.Name, item, duplicate_check.Add(data)));
                                        }
                                    }

                                    n++;
                                }
                            }
                            else
                            {
                                if (duplicate_check.Contains(data) == false)
                                {
                                    ret.Childlen.Add(GetVarsFromClass(data_type, info.Name, data, duplicate_check.Add(data)));
                                }
                            }
                        }
                    }
                }
            }

            ret.BaseName = name;

            return(ret);
        }
예제 #4
0
        public static string GetObjectInnerString(Type t, object obj, string instance_base_name)
        {
            DebugVars v = GetVarsFromClass(t, instance_base_name, obj);

            return(v.ToString());
        }