public void AnonymousObjectsRenderAsCode()
        {
            Assert.Equal(@"new {
    A = 1,
    Foo = ""Bar"",
}", ObjectToCode.ComplexObjectToPseudoCode(new { A = 1, Foo = "Bar", }));
        }
 static object PrettyPrintField(FieldInfo fi)
 {
     return("    "
            + (fi.IsLiteral ? "const " : (fi.IsStatic ? "static " : "") + (fi.IsInitOnly ? "readonly " : ""))
            + ObjectToCode.GetCSharpFriendlyTypeName(fi.FieldType)
            + " " + fi.Name
            + (fi.IsLiteral ? " = " + ObjectToCode.ComplexObjectToPseudoCode(fi.GetRawConstantValue()) : "")
            );
 }
Example #3
0
        public void AnonymousObjectsInArray()
        => Assert.Equal(
            @"new[] {
    new {
        Val = 3,
    },
    new {
        Val = 42,
    },
}",
            ObjectToCode.ComplexObjectToPseudoCode(new[] { new { Val = 3, }, new { Val = 42 } }));
Example #4
0
        public void InsertsLineBreaksContentsContainLineBreaks()
        => Assert.Equal(
            @"{
    new {
        A = 3,
        B = 'b',
    },
    new {
        A = 3,
        B = 'b',
    },
}".Replace("\r", ""),
            ObjectToCode.ComplexObjectToPseudoCode(Enumerable.Repeat(new { A = 3, B = 'b' }, 2)));
 public void ComplexObjectToCodeAlsoSupportsExpressions()
 => Assert.Equal("() => 42", ObjectToCode.ComplexObjectToPseudoCode((Expression <Func <int> >)(() => 42)));
Example #6
0
 public void LongArraysDoNotBreakAfter30_InCodeGen()
 => Assert.Equal("new[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32 }", ObjectToCode.ComplexObjectToPseudoCode(Enumerable.Range(1, 32).ToArray()));
Example #7
0
 public void ShortEnumerablesRenderedCompletely()
 => Assert.Equal("{ 1, 2, 3 }", ObjectToCode.ComplexObjectToPseudoCode(Enumerable.Range(1, 3)));
Example #8
0
 public void ShortArraysRenderedCompletely()
 => Assert.Equal("new[] { 1, 2, 3 }", ObjectToCode.ComplexObjectToPseudoCode(new[] { 1, 2, 3 }));
        public void EnumInAnonymousObject()
        {
            Assert.Equal(@"new {
    Enum = ConsoleKey.A,
}", ObjectToCode.ComplexObjectToPseudoCode(new { Enum = ConsoleKey.A }));
        }
Example #10
0
 public void LongArraysDoNotBreakAfter15_InCodeGen()
 {
     Assert.Equal("new[] {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18}", ObjectToCode.ComplexObjectToPseudoCode(Enumerable.Range(1, 18).ToArray()));
 }