protected virtual CommonPrimitiveFormatterOptions GetPrimitiveOptions(PrintOptions printOptions) =>
     new CommonPrimitiveFormatterOptions(
         numberRadix: printOptions.NumberRadix,
         includeCodePoints: false,
         quoteStringsAndCharacters: true,
         escapeNonPrintableCharacters: printOptions.EscapeNonPrintableCharacters,
         cultureInfo: CultureInfo.CurrentUICulture);
示例#2
0
 protected virtual CommonPrimitiveFormatterOptions GetPrimitiveOptions(PrintOptions printOptions) =>
 new CommonPrimitiveFormatterOptions(
     numberRadix: printOptions.NumberRadix,
     includeCodePoints: false,
     quoteStringsAndCharacters: true,
     escapeNonPrintableCharacters: printOptions.EscapeNonPrintableCharacters,
     cultureInfo: CultureInfo.CurrentUICulture);
 internal virtual BuilderOptions GetInternalBuilderOptions(PrintOptions printOptions) =>
     new BuilderOptions(
         indentation: "  ",
         newLine: Environment.NewLine,
         ellipsis: printOptions.Ellipsis,
         maximumLineLength: int.MaxValue,
         maximumOutputLength: printOptions.MaximumOutputLength);
示例#4
0
 protected virtual CommonTypeNameFormatterOptions GetTypeNameOptions(
     PrintOptions printOptions
     ) =>
 new CommonTypeNameFormatterOptions(
     arrayBoundRadix: printOptions.NumberRadix,
     showNamespaces: false
     );
示例#5
0
 protected virtual BuilderOptions GetInternalBuilderOptions(PrintOptions printOptions) =>
 new BuilderOptions(
     indentation: "  ",
     newLine: Environment.NewLine,
     ellipsis: printOptions.Ellipsis,
     maximumLineLength: int.MaxValue,
     maximumOutputLength: printOptions.MaximumOutputLength);
示例#6
0
        public void ValidEscapeNonPrintableCharacters()
        {
            var options = new PrintOptions();

            options.EscapeNonPrintableCharacters = true;
            Assert.Equal(@"""\t""", s_formatter.FormatObject("\t", options));
            Assert.Equal(@"'\t'", s_formatter.FormatObject('\t', options));

            options.EscapeNonPrintableCharacters = false;
            Assert.Equal("\"\t\"", s_formatter.FormatObject("\t", options));
            Assert.Equal("'\t'", s_formatter.FormatObject('\t', options));
        }
        public override string FormatObject(object obj, PrintOptions options)
        {
            if (options == null)
            {
                // We could easily recover by using default options, but it makes
                // more sense for the host to choose the defaults so we'll require
                // that options be passed.
                throw new ArgumentNullException(nameof(options));
            }

            var visitor = new Visitor(this, GetInternalBuilderOptions(options), GetPrimitiveOptions(options), GetTypeNameOptions(options), options.MemberDisplayFormat);
            return visitor.FormatObject(obj);
        }
示例#8
0
        public override string FormatObject(object obj, PrintOptions options)
        {
            if (options == null)
            {
                // We could easily recover by using default options, but it makes
                // more sense for the host to choose the defaults so we'll require
                // that options be passed.
                throw new ArgumentNullException(nameof(options));
            }

            var visitor = new Visitor(this, GetInternalBuilderOptions(options), GetPrimitiveOptions(options), GetTypeNameOptions(options), options.MemberDisplayFormat);

            return(visitor.FormatObject(obj));
        }
示例#9
0
        public void ValidNumberRadix()
        {
            var formatter = new TestCSharpObjectFormatter(includeCodePoints: true);
            var options = new PrintOptions();

            options.NumberRadix = 10;
            Assert.Equal("10", formatter.FormatObject(10, options));
            Assert.Equal("int[10] { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }", formatter.FormatObject(new int[10], options));
            Assert.Equal(@"16 '\u0010'", formatter.FormatObject('\u0010', options));

            options.NumberRadix = 16;
            Assert.Equal("0x0000000a", formatter.FormatObject(10, options));
            Assert.Equal("int[0x0000000a] { 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000 }", formatter.FormatObject(new int[10], options));
            Assert.Equal(@"0x0010 '\u0010'", formatter.FormatObject('\u0010', options));
        }
示例#10
0
        public CommandLineScriptGlobals(TextWriter outputWriter, ObjectFormatter objectFormatter)
        {
            if (outputWriter == null)
            {
                throw new ArgumentNullException(nameof(outputWriter));
            }

            if (objectFormatter == null)
            {
                throw new ArgumentNullException(nameof(objectFormatter));
            }

            PrintOptions = new PrintOptions();

            _outputWriter    = outputWriter;
            _objectFormatter = objectFormatter;

            Args = new List <string>();
        }
示例#11
0
        public CommandLineScriptGlobals(TextWriter outputWriter, ObjectFormatter objectFormatter)
        {
            if (outputWriter == null)
            {
                throw new ArgumentNullException(nameof(outputWriter));
            }

            if (objectFormatter == null)
            {
                throw new ArgumentNullException(nameof(objectFormatter));
            }

            PrintOptions = new PrintOptions();

            _outputWriter = outputWriter;
            _objectFormatter = objectFormatter;

            Args = new List<string>();
        }
示例#12
0
        public void ValidMemberDisplayFormat()
        {
            var options = new PrintOptions();

            options.MemberDisplayFormat = MemberDisplayFormat.Hidden;
            Assert.Equal("PrintOptions", s_formatter.FormatObject(options, options));

            options.MemberDisplayFormat = MemberDisplayFormat.SingleLine;
            Assert.Equal("PrintOptions { Ellipsis=\"...\", EscapeNonPrintableCharacters=true, MaximumOutputLength=1024, MemberDisplayFormat=SingleLine, NumberRadix=10 }", s_formatter.FormatObject(options, options));

            options.MemberDisplayFormat = MemberDisplayFormat.SeparateLines;
            Assert.Equal(@"PrintOptions {
  Ellipsis: ""..."",
  EscapeNonPrintableCharacters: true,
  MaximumOutputLength: 1024,
  MemberDisplayFormat: SeparateLines,
  NumberRadix: 10,
  _maximumOutputLength: 1024,
  _memberDisplayFormat: SeparateLines,
  _numberRadix: 10
}
", s_formatter.FormatObject(options, options));
        }
示例#13
0
        public InteractiveScriptGlobals(TextWriter outputWriter, ObjectFormatter objectFormatter)
        {
            if (outputWriter == null)
            {
                throw new ArgumentNullException(nameof(outputWriter));
            }

            if (objectFormatter == null)
            {
                throw new ArgumentNullException(nameof(objectFormatter));
            }

            Debug.Assert(outputWriter != null);
            Debug.Assert(objectFormatter != null);

            ReferencePaths = new SearchPaths();
            SourcePaths = new SearchPaths();
            Args = new List<string>();

            PrintOptions = new PrintOptions();

            _outputWriter = outputWriter;
            _objectFormatter = objectFormatter;
        }
示例#14
0
        public InteractiveScriptGlobals(TextWriter outputWriter, ObjectFormatter objectFormatter)
        {
            if (outputWriter == null)
            {
                throw new ArgumentNullException(nameof(outputWriter));
            }

            if (objectFormatter == null)
            {
                throw new ArgumentNullException(nameof(objectFormatter));
            }

            Debug.Assert(outputWriter != null);
            Debug.Assert(objectFormatter != null);

            ReferencePaths = new SearchPaths();
            SourcePaths    = new SearchPaths();
            Args           = new List <string>();

            PrintOptions = new PrintOptions();

            _outputWriter    = outputWriter;
            _objectFormatter = objectFormatter;
        }
示例#15
0
        public void ValidMaximumOutputLength()
        {
            var options = new PrintOptions();

            options.MaximumOutputLength = 1;
            Assert.Equal("1...", s_formatter.FormatObject(123456, options));

            options.MaximumOutputLength = 2;
            Assert.Equal("12...", s_formatter.FormatObject(123456, options));

            options.MaximumOutputLength = 3;
            Assert.Equal("123...", s_formatter.FormatObject(123456, options));

            options.MaximumOutputLength = 4;
            Assert.Equal("1234...", s_formatter.FormatObject(123456, options));

            options.MaximumOutputLength = 5;
            Assert.Equal("12345...", s_formatter.FormatObject(123456, options));

            options.MaximumOutputLength = 6;
            Assert.Equal("123456", s_formatter.FormatObject(123456, options));

            options.MaximumOutputLength = 7;
            Assert.Equal("123456", s_formatter.FormatObject(123456, options));
        }
示例#16
0
        public void ValidEllipsis()
        {
            var options = new PrintOptions();
            options.MaximumOutputLength = 1;

            options.Ellipsis = ".";
            Assert.Equal("1.", s_formatter.FormatObject(123456, options));

            options.Ellipsis = "..";
            Assert.Equal("1..", s_formatter.FormatObject(123456, options));

            options.Ellipsis = "";
            Assert.Equal("1", s_formatter.FormatObject(123456, options));

            options.Ellipsis = null;
            Assert.Equal("1", s_formatter.FormatObject(123456, options));
        }
示例#17
0
		public PrintOptionsImpl() {
			printOptions = new PrintOptions();
			AutoColorizeObjects = true;
		}
示例#18
0
 public abstract string FormatObject(object obj, PrintOptions options);
示例#19
0
 protected virtual CommonTypeNameFormatterOptions GetTypeNameOptions(PrintOptions printOptions) =>
     new CommonTypeNameFormatterOptions(
         arrayBoundRadix: printOptions.NumberRadix,
         showNamespaces: false);
示例#20
0
 public abstract string FormatObject(object obj, PrintOptions options);
 public override string FormatObject(object obj, PrintOptions options) => _impl.FormatObject(obj, options);
示例#22
0
		public PrintOptionsImpl() {
			this.printOptions = new PrintOptions();
		}