コード例 #1
0
            private CommonObjectFormatter.Builder FormatObjectRecursive(
                CommonObjectFormatter.Builder result,
                object obj,
                bool isRoot)
            {
                string str = this._formatter.PrimitiveFormatter.FormatPrimitive(obj, this._primitiveOptions);

                if (str != null)
                {
                    result.Append(str, 0, int.MaxValue);
                    return(result);
                }
                Type type = obj.GetType();

                System.Reflection.TypeInfo typeInfo = IntrospectionExtensions.GetTypeInfo(type);
                if (typeInfo.IsGenericType && typeInfo.GetGenericTypeDefinition() == (object)typeof(KeyValuePair <,>))
                {
                    if (isRoot)
                    {
                        result.Append(this._formatter.TypeNameFormatter.FormatTypeName(type), 0, int.MaxValue);
                        result.Append(' ');
                    }
                    this.FormatKeyValuePair(result, obj);
                    return(result);
                }
                if (typeInfo.IsArray)
                {
                    if (this.VisitedObjects.Add(obj))
                    {
                        this.FormatArray(result, (Array)obj);
                        this.VisitedObjects.Remove(obj);
                    }
                    else
                    {
                        result.AppendInfiniteRecursionMarker();
                    }
                    return(result);
                }
                bool        flag       = false;
                ICollection collection = null;

                if (obj is ICollection)
                {
                    collection = (ICollection)obj;
                    this.FormatCollectionHeader(result, collection);
                }
                else if (ObjectFormatterHelpers.HasOverriddenToString(typeInfo))
                {
                    this.ObjectToString(result, obj);
                    flag = true;
                }
                else
                {
                    result.Append(this._formatter.TypeNameFormatter.FormatTypeName(type), 0, int.MaxValue);
                }

                if (!flag)
                {
                    this.FormatMembers(result, obj);
                }
                return(result);
            }