Example #1
0
        protected override int VisitStructureValue(ThemedValueFormatterState state, StructureValue structure)
        {
            var count = 0;

            if (structure.TypeTag != null)
            {
                using (ApplyStyle(state.Output, RichTextBoxThemeStyle.Name, ref count))
                {
                    state.Output.Write(structure.TypeTag);
                }

                state.Output.Write(' ');
            }

            using (ApplyStyle(state.Output, RichTextBoxThemeStyle.TertiaryText, ref count))
            {
                state.Output.Write('{');
            }

            var delim = string.Empty;

            // ReSharper disable once ForCanBeConvertedToForeach
            for (var index = 0; index < structure.Properties.Count; ++index)
            {
                if (delim.Length != 0)
                {
                    using (ApplyStyle(state.Output, RichTextBoxThemeStyle.TertiaryText, ref count))
                    {
                        state.Output.Write(delim);
                    }
                }

                delim = ", ";

                var property = structure.Properties[index];

                using (ApplyStyle(state.Output, RichTextBoxThemeStyle.Name, ref count))
                {
                    var escapedPropertyName = SpecialCharsEscaping.Apply(property.Name, ref count);
                    state.Output.Write(escapedPropertyName);
                }

                using (ApplyStyle(state.Output, RichTextBoxThemeStyle.TertiaryText, ref count))
                {
                    state.Output.Write('=');
                }

                count += Visit(state.Nest(), property.Value);
            }

            using (ApplyStyle(state.Output, RichTextBoxThemeStyle.TertiaryText, ref count))
            {
                state.Output.Write('}');
            }

            return count;
        }
Example #2
0
        protected override int VisitScalarValue(ThemedValueFormatterState state, ScalarValue scalar)
        {
            if (scalar is null)
            {
                throw new ArgumentNullException(nameof(scalar));
            }

            return FormatLiteralValue(scalar, state.Output, state.Format);
        }
Example #3
0
        protected override int VisitDictionaryValue(ThemedValueFormatterState state, DictionaryValue dictionary)
        {
            var count = 0;

            using (ApplyStyle(state.Output, RichTextBoxThemeStyle.TertiaryText, ref count))
            {
                state.Output.Write('{');
            }

            var delim = string.Empty;

            foreach (var element in dictionary.Elements)
            {
                if (delim.Length != 0)
                {
                    using (ApplyStyle(state.Output, RichTextBoxThemeStyle.TertiaryText, ref count))
                    {
                        state.Output.Write(delim);
                    }
                }

                delim = ", ";

                var style = element.Key.Value is null
                    ? RichTextBoxThemeStyle.Null
                    : element.Key.Value is string
                            ?RichTextBoxThemeStyle.String
                            : RichTextBoxThemeStyle.Scalar;

                using (ApplyStyle(state.Output, style, ref count))
                {
                    var escapedKey = SpecialCharsEscaping.Apply((element.Key.Value ?? "null").ToString(), ref count);
                    JsonValueFormatter.WriteQuotedJsonString(escapedKey, state.Output);
                }

                using (ApplyStyle(state.Output, RichTextBoxThemeStyle.TertiaryText, ref count))
                {
                    state.Output.Write(": ");
                }

                count += Visit(state.Nest(), element.Value);
            }

            using (ApplyStyle(state.Output, RichTextBoxThemeStyle.TertiaryText, ref count))
            {
                state.Output.Write('}');
            }

            return(count);
        }
Example #4
0
        protected override int VisitScalarValue(ThemedValueFormatterState state, ScalarValue scalar)
        {
            if (scalar is null)
            {
                throw new ArgumentNullException(nameof(scalar));
            }

            // At the top level, for scalar values, use "display" rendering.
            if (state.IsTopLevel)
            {
                return(_displayFormatter.FormatLiteralValue(scalar, state.Output, state.Format));
            }

            return(FormatLiteralValue(scalar, state.Output));
        }
Example #5
0
        protected override int VisitDictionaryValue(ThemedValueFormatterState state, DictionaryValue dictionary)
        {
            var count = 0;

            using (ApplyStyle(state.Output, RichTextBoxThemeStyle.TertiaryText, ref count))
            {
                state.Output.Write('{');
            }

            var delim = string.Empty;
            foreach (var element in dictionary.Elements)
            {
                if (delim.Length != 0)
                {
                    using (ApplyStyle(state.Output, RichTextBoxThemeStyle.TertiaryText, ref count))
                    {
                        state.Output.Write(delim);
                    }
                }

                delim = ", ";

                using (ApplyStyle(state.Output, RichTextBoxThemeStyle.TertiaryText, ref count))
                {
                    state.Output.Write('[');
                }

                using (ApplyStyle(state.Output, RichTextBoxThemeStyle.String, ref count))
                {
                    count += Visit(state.Nest(), element.Key);
                }

                using (ApplyStyle(state.Output, RichTextBoxThemeStyle.TertiaryText, ref count))
                {
                    state.Output.Write("]=");
                }

                count += Visit(state.Nest(), element.Value);
            }

            using (ApplyStyle(state.Output, RichTextBoxThemeStyle.TertiaryText, ref count))
            {
                state.Output.Write('}');
            }

            return count;
        }
Example #6
0
        protected override int VisitSequenceValue(ThemedValueFormatterState state, SequenceValue sequence)
        {
            if (sequence is null)
            {
                throw new ArgumentNullException(nameof(sequence));
            }

            var count = 0;

            using (ApplyStyle(state.Output, RichTextBoxThemeStyle.TertiaryText, ref count))
            {
                state.Output.Write('[');
            }

            var delim = string.Empty;

            // ReSharper disable once ForCanBeConvertedToForeach
            for (var index = 0; index < sequence.Elements.Count; ++index)
            {
                if (delim.Length != 0)
                {
                    using (ApplyStyle(state.Output, RichTextBoxThemeStyle.TertiaryText, ref count))
                    {
                        state.Output.Write(delim);
                    }
                }

                delim = ", ";
                Visit(state, sequence.Elements[index]);
            }

            using (ApplyStyle(state.Output, RichTextBoxThemeStyle.TertiaryText, ref count))
            {
                state.Output.Write(']');
            }

            return count;
        }