当前位置: 首页>>代码示例>>C#>>正文


C# Builder.AppendInfiniteRecursionMarker方法代码示例

本文整理汇总了C#中Builder.AppendInfiniteRecursionMarker方法的典型用法代码示例。如果您正苦于以下问题:C# Builder.AppendInfiniteRecursionMarker方法的具体用法?C# Builder.AppendInfiniteRecursionMarker怎么用?C# Builder.AppendInfiniteRecursionMarker使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Builder的用法示例。


在下文中一共展示了Builder.AppendInfiniteRecursionMarker方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: FormatObjectRecursive

            private Builder FormatObjectRecursive(Builder result, object obj, bool isRoot, out string debuggerDisplayName)
            {
                // TODO (https://github.com/dotnet/roslyn/issues/6689): remove this
                if (!isRoot && _memberDisplayFormat == MemberDisplayFormat.SeparateLines)
                {
                    _memberDisplayFormat = MemberDisplayFormat.SingleLine;
                }

                debuggerDisplayName = null;
                string primitive = _formatter.PrimitiveFormatter.FormatPrimitive(obj, _primitiveOptions);
                if (primitive != null)
                {
                    result.Append(primitive);
                    return result;
                }

                Type type = obj.GetType();
                TypeInfo typeInfo = type.GetTypeInfo();

                //
                // Override KeyValuePair<,>.ToString() to get better dictionary elements formatting:
                //
                // { { format(key), format(value) }, ... }
                // instead of
                // { [key.ToString(), value.ToString()], ... } 
                //
                // This is more general than overriding Dictionary<,> debugger proxy attribute since it applies on all
                // types that return an array of KeyValuePair in their DebuggerDisplay to display items.
                //
                if (typeInfo.IsGenericType && typeInfo.GetGenericTypeDefinition() == typeof(KeyValuePair<,>))
                {
                    if (isRoot)
                    {
                        result.Append(_formatter.TypeNameFormatter.FormatTypeName(type, _typeNameOptions));
                        result.Append(' ');
                    }

                    FormatKeyValuePair(result, obj);
                    return result;
                }

                if (typeInfo.IsArray)
                {
                    if (VisitedObjects.Add(obj))
                    {
                        FormatArray(result, (Array)obj);

                        VisitedObjects.Remove(obj);
                    }
                    else
                    {
                        result.AppendInfiniteRecursionMarker();
                    }

                    return result;
                }

                DebuggerDisplayAttribute debuggerDisplay = GetApplicableDebuggerDisplayAttribute(typeInfo);
                if (debuggerDisplay != null)
                {
                    debuggerDisplayName = debuggerDisplay.Name;
                }

                // Suppresses members if inlineMembers is true,
                // does nothing otherwise.
                bool suppressInlineMembers = false;

                //
                // TypeName(count) for ICollection implementers
                // or
                // TypeName([[DebuggerDisplay.Value]])        // Inline
                // [[DebuggerDisplay.Value]]                  // Inline && !isRoot
                // or
                // [[ToString()]] if ToString overridden
                // or
                // TypeName 
                // 
                ICollection collection;
                if ((collection = obj as ICollection) != null)
                {
                    FormatCollectionHeader(result, collection);
                }
                else if (debuggerDisplay != null && !string.IsNullOrEmpty(debuggerDisplay.Value))
                {
                    if (isRoot)
                    {
                        result.Append(_formatter.TypeNameFormatter.FormatTypeName(type, _typeNameOptions));
                        result.Append('(');
                    }

                    FormatWithEmbeddedExpressions(result, debuggerDisplay.Value, obj);

                    if (isRoot)
                    {
                        result.Append(')');
                    }

                    suppressInlineMembers = true;
                }
                else if (HasOverriddenToString(typeInfo))
//.........这里部分代码省略.........
开发者ID:CAPCHIK,项目名称:roslyn,代码行数:101,代码来源:CommonObjectFormatter.Visitor.cs

示例2: FormatObjectRecursive

            private Builder FormatObjectRecursive(Builder result, object obj, bool quoteStrings, MemberDisplayFormat memberFormat, out string name)
            {
                name = null;
                string primitive = _language.FormatPrimitive(obj, quoteStrings, _options.IncludeCodePoints, _options.UseHexadecimalNumbers);
                if (primitive != null)
                {
                    result.Append(primitive);
                    return result;
                }

                object originalObj = obj;
                Type originalType = originalObj.GetType();

                //
                // Override KeyValuePair<,>.ToString() to get better dictionary elements formatting:
                //
                // { { format(key), format(value) }, ... }
                // instead of
                // { [key.ToString(), value.ToString()], ... } 
                //
                // This is more general than overriding Dictionary<,> debugger proxy attribute since it applies on all
                // types that return an array of KeyValuePair in their DebuggerDisplay to display items.
                //
                if (originalType.IsGenericType && originalType.GetGenericTypeDefinition() == typeof(KeyValuePair<,>))
                {
                    if (memberFormat != MemberDisplayFormat.InlineValue)
                    {
                        result.Append(_language.FormatTypeName(originalType, _options));
                        result.Append(' ');
                    }

                    FormatKeyValuePair(result, originalObj);
                    return result;
                }

                if (originalType.IsArray)
                {
                    if (!VisitedObjects.Add(originalObj))
                    {
                        result.AppendInfiniteRecursionMarker();
                        return result;
                    }

                    FormatArray(result, (Array)originalObj, inline: memberFormat != MemberDisplayFormat.List);

                    VisitedObjects.Remove(originalObj);
                    return result;
                }

                DebuggerDisplayAttribute debuggerDisplay = GetApplicableDebuggerDisplayAttribute(originalType);
                if (debuggerDisplay != null)
                {
                    name = debuggerDisplay.Name;
                }

                bool suppressMembers = false;

                //
                // TypeName(count) for ICollection implementers
                // or
                // TypeName([[DebuggerDisplay.Value]])        // Inline
                // [[DebuggerDisplay.Value]]                  // InlineValue
                // or
                // [[ToString()]] if ToString overridden
                // or
                // TypeName 
                // 
                ICollection collection;
                if ((collection = originalObj as ICollection) != null)
                {
                    FormatCollectionHeader(result, collection);
                }
                else if (debuggerDisplay != null && !String.IsNullOrEmpty(debuggerDisplay.Value))
                {
                    if (memberFormat != MemberDisplayFormat.InlineValue)
                    {
                        result.Append(_language.FormatTypeName(originalType, _options));
                        result.Append('(');
                    }

                    FormatWithEmbeddedExpressions(result, debuggerDisplay.Value, originalObj);

                    if (memberFormat != MemberDisplayFormat.InlineValue)
                    {
                        result.Append(')');
                    }

                    suppressMembers = true;
                }
                else if (HasOverriddenToString(originalType))
                {
                    ObjectToString(result, originalObj);
                    suppressMembers = true;
                }
                else
                {
                    result.Append(_language.FormatTypeName(originalType, _options));
                }

                if (memberFormat == MemberDisplayFormat.NoMembers)
//.........这里部分代码省略.........
开发者ID:ehsansajjad465,项目名称:roslyn,代码行数:101,代码来源:ObjectFormatter.Formatter.cs

示例3: FormatMembers

            private void FormatMembers(Builder result, object obj, object proxy, bool includeNonPublic, bool inlineMembers)
            {
                // TODO (tomat): we should not use recursion
                RuntimeHelpers.EnsureSufficientExecutionStack();

                result.Append(' ');

                // Note: Even if we've seen it before, we show a header 
                if (!VisitedObjects.Add(obj))
                {
                    result.AppendInfiniteRecursionMarker();
                    return;
                }

                bool membersFormatted = false;

                // handle special types only if a proxy isn't defined
                if (proxy == null)
                {
                    IDictionary dictionary;
                    IEnumerable enumerable;
                    if ((dictionary = obj as IDictionary) != null)
                    {
                        FormatDictionaryMembers(result, dictionary, inlineMembers);
                        membersFormatted = true;
                    }
                    else if ((enumerable = obj as IEnumerable) != null)
                    {
                        FormatSequenceMembers(result, enumerable, inlineMembers);
                        membersFormatted = true;
                    }
                }

                if (!membersFormatted)
                {
                    FormatObjectMembers(result, proxy ?? obj, obj.GetType().GetTypeInfo(), includeNonPublic, inlineMembers);
                }

                VisitedObjects.Remove(obj);
            }
开发者ID:CAPCHIK,项目名称:roslyn,代码行数:40,代码来源:CommonObjectFormatter.Visitor.cs


注:本文中的Builder.AppendInfiniteRecursionMarker方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。