Пример #1
0
        public void NestedObjects()
        {
            var obj = new TestClass3
            {
                Class1 = new TestClass1 {
                    Test = 6
                },
                Class2 = new TestClass2 {
                    Test = "Hello world"
                }
            };

            var result   = SourceCodeSerializer.Serialize(obj);
            var expected = @"new SourceCodeSerializer.TestClass3
{
    Class1 = new SourceCodeSerializer.TestClass1
    {
        Test = 6
    },
    Class2 = new SourceCodeSerializer.TestClass2
    {
        Test = @""Hello world""
    }
}";

            _helper.WriteLine(result);
            Assert.Equal(result, expected);
        }
Пример #2
0
        public void NestedObjectsWithClassAndUsings()
        {
            var obj = new TestClass3
            {
                Class1 = new TestClass1 {
                    Test = 6
                },
                Class2 = new TestClass2 {
                    Test = "Hello world"
                }
            };

            var settings = new SerializerSettings
            {
                Generator = new FactoryMethodGenerator("Test", "Factory", "Create"),
                Usings    = ImmutableArray.Create("System", "SourceCodeSerializer")
            };

            var result = SourceCodeSerializer.Serialize(obj, settings);

            var expected = @"using System;
using SourceCodeSerializer;

namespace Test
{
    partial class Factory
    {
        public TestClass3 Create()
        {
            return new TestClass3
            {
                Class1 = new TestClass1
                {
                    Test = 6
                },
                Class2 = new TestClass2
                {
                    Test = @""Hello world""
                }
            };
        }
    }
}";

            _helper.WriteLine(result);
            Assert.Equal(result, expected);
        }