예제 #1
0
 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);
예제 #3
0
 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));
        }
예제 #7
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);
        }
예제 #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);
예제 #21
0
 public override string FormatObject(object obj, PrintOptions options) => _impl.FormatObject(obj, options);
예제 #22
0
		public PrintOptionsImpl() {
			this.printOptions = new PrintOptions();
		}