示例#1
0
        void WriteObject(YamlObject obj, bool allowInlining)
        {
            if (obj is null)
            {
                // Nulls are always written inline.
                WriteInline("~");
            }
            else
            {
                switch (obj.Kind)
                {
                case YamlObjectKind.Scalar:
                    WriteScalar((YamlScalar)obj, allowInlining);
                    break;

                case YamlObjectKind.Map:
                    WriteMap((YamlMap)obj, allowInlining);
                    break;

                case YamlObjectKind.Sequence:
                    WriteSequence((YamlSequence)obj, allowInlining);
                    break;

                default:
                    throw new InvalidOperationException();
                }
            }
        }
示例#2
0
        bool TryInlineObject(YamlObject obj, int maximumWidth, [MaybeNullWhen(false)] out string result)
        {
            if (maximumWidth < 1)
            {
                result = null;
                return(false);
            }
            else if (obj is null)
            {
                result = "~";
                return(true);
            }
            else
            {
                switch (obj.Kind)
                {
                case YamlObjectKind.Scalar: return(TryInlineScalar((YamlScalar)obj, maximumWidth, out result));

                case YamlObjectKind.Map: return(TryInlineMap((YamlMap)obj, maximumWidth, out result));

                case YamlObjectKind.Sequence: return(TryInlineSequence((YamlSequence)obj, maximumWidth, out result));

                default: throw new InvalidOperationException();
                }
            }
        }
示例#3
0
        /// <summary>
        /// Writes the given object to the output.
        /// </summary>
        /// <param name="obj">The object to write.</param>
        public void WriteObject(YamlObject obj)
        {
            if (obj == null)
            {
                WriteInline("~");
            }
            else
            {
                switch (obj.Kind)
                {
                case YamlObjectKind.Scalar:
                    WriteScalar((YamlScalar)obj);
                    break;

                case YamlObjectKind.Map:
                    WriteMap((YamlMap)obj);
                    break;

                case YamlObjectKind.Sequence:
                    WriteSequence((YamlSequence)obj);
                    break;

                default:
                    throw new InvalidOperationException();
                }
            }
        }
示例#4
0
        bool TryWriteComment(YamlObject obj)
        {
            if (obj?.Comment is null)
            {
                return(false);
            }

            // We only support single line comments. Filter out newlines and other
            // non-printable characters.
            var cleanComment = new string(FilterNonPrintingCharacters(obj.Comment).ToArray());

            Write($"# {cleanComment}");
            return(true);
        }
示例#5
0
 public void WriteObject(YamlObject obj)
 => WriteObject(obj, allowInlining: true);