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);
protected virtual CommonTypeNameFormatterOptions GetTypeNameOptions( PrintOptions printOptions ) => new CommonTypeNameFormatterOptions( arrayBoundRadix: printOptions.NumberRadix, showNamespaces: false );
protected virtual BuilderOptions GetInternalBuilderOptions(PrintOptions printOptions) => new BuilderOptions( indentation: " ", newLine: Environment.NewLine, ellipsis: printOptions.Ellipsis, maximumLineLength: int.MaxValue, maximumOutputLength: printOptions.MaximumOutputLength);
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); }
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)); }
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)); }
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>(); }
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>(); }
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)); }
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; }
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; }
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)); }
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)); }
public PrintOptionsImpl() { printOptions = new PrintOptions(); AutoColorizeObjects = true; }
public abstract string FormatObject(object obj, PrintOptions options);
protected virtual CommonTypeNameFormatterOptions GetTypeNameOptions(PrintOptions printOptions) => new CommonTypeNameFormatterOptions( arrayBoundRadix: printOptions.NumberRadix, showNamespaces: false);
public override string FormatObject(object obj, PrintOptions options) => _impl.FormatObject(obj, options);
public PrintOptionsImpl() { this.printOptions = new PrintOptions(); }