public void PropertiesAndFields1() { var test1 = new Test1(); test1.PublicField = 2; test1.PublicProp = 3; test1.ClassPropByAssign.Add("abc"); test1.ReadOnlyClassProp.Add("def"); test1.ClassPropByContent.Add("ghi"); var rand = new Random(0); for (int i = 0; i < test1.IntArrayFieldBinary.Length; i++) { test1.IntArrayFieldBinary[i] = rand.Next(); } string yaml = serializer.Serialize(test1); // %YAML 1.2 // --- // !YamlSerializerTest.Test1 // PublicProp: 0 // ReadOnlyClassProp: // Capacity: 4 // ICollection.Items: // - abc // ClassPropByContent: // Capacity: 0 // PublicField: 0 // IntArrayFieldBinary: |+2 // Gor1XAwenmhGkU5ib9NxR11LXxp1iYlH5LH4c9hImTitWSB9Z78II2UvXSXV99A79fj6UBn3GDzbIbd9 // yBDjAyslYm58iGd/NN+tVjuLRCg3cJBo+PWMbIWm9n4AEC0E7LKXWV5HXUNk7I13APEDWFMM/kWTz2EK // s7LzFw2gBjpKugkmQJqIfinpQ1J1yqhhz/XjA3TBxDBsEuwrD+SNevQSqEC+/KRbwgE6D011ACMeyRt0 // BOG6ZesRKCtL0YU6tSnLEpgKVBz+R300qD3/W0aZVk+1vHU+auzyGCGUaHCGd6dpRoEhXoIg2m3+AwJX // EJ37T+TA9BuEPJtyGoq+crQMFQtXj1Zriz3HFbReclLvDdVpZlcOHPga/3+3Y509EHZ7UyT7H1xGeJxn // eXPrDDb0Ul04MfZb4UYREOfR3HNzNTUYGRsIPUvHOEW7AaoplIfkVQp19DvGBrBqlP2TZ9atlWUHVdth // 7lIBeIh0wiXxoOpCbQ7qVP9GkioQUrMkOcAJaad3exyZaOsXxznFCA== // ... Assert.AreEqual( BuildResult( "!YamlSerializerTest.Test1", "IntArrayField: [0, 0, 0, 0, 0, 0, 0, 0, 0, 0]", "PublicField: 2", "IntArrayFieldBinary: |+2", " Gor1XAwenmhGkU5ib9NxR11LXxp1iYlH5LH4c9hImTitWSB9Z78II2UvXSXV99A79fj6UBn3GDzbIbd9", " yBDjAyslYm58iGd/NN+tVjuLRCg3cJBo+PWMbIWm9n4AEC0E7LKXWV5HXUNk7I13APEDWFMM/kWTz2EK", " s7LzFw2gBjpKugkmQJqIfinpQ1J1yqhhz/XjA3TBxDBsEuwrD+SNevQSqEC+/KRbwgE6D011ACMeyRt0", " BOG6ZesRKCtL0YU6tSnLEpgKVBz+R300qD3/W0aZVk+1vHU+auzyGCGUaHCGd6dpRoEhXoIg2m3+AwJX", " EJ37T+TA9BuEPJtyGoq+crQMFQtXj1Zriz3HFbReclLvDdVpZlcOHPga/3+3Y509EHZ7UyT7H1xGeJxn", " eXPrDDb0Ul04MfZb4UYREOfR3HNzNTUYGRsIPUvHOEW7AaoplIfkVQp19DvGBrBqlP2TZ9atlWUHVdth", " 7lIBeIh0wiXxoOpCbQ7qVP9GkioQUrMkOcAJaad3exyZaOsXxznFCA==", "ReadOnlyClassProp: ", " Capacity: 4", " ICollection.Items: ", " - def", "ClassPropByAssign: ", " Capacity: 4", " ICollection.Items: ", " - abc", "PublicProp: 3", "ClassPropByContent: ", " Capacity: 4", " ICollection.Items: ", " - ghi" ), yaml); object restored = serializer.Deserialize(yaml)[0]; Assert.AreEqual(test1.PublicField, ((Test1)restored).PublicField); Assert.AreEqual(test1.PublicProp, ((Test1)restored).PublicProp); Assert.AreEqual(test1.ReadOnlyClassProp, ((Test1)restored).ReadOnlyClassProp); Assert.AreEqual(test1.ClassPropByContent, ((Test1)restored).ClassPropByContent); Assert.AreEqual(test1.IntArrayFieldBinary, ((Test1)restored).IntArrayFieldBinary); }
public void PropertiesAndFields1() { var test1 = new Test1(); test1.PublicField = 2; test1.PublicProp = 3; test1.ClassPropByAssign.Add("abc"); test1.ReadOnlyClassProp.Add("def"); test1.ClassPropByContent.Add("ghi"); var rand = new Random(0); for ( int i = 0; i < test1.IntArrayFieldBinary.Length; i++ ) test1.IntArrayFieldBinary[i] = rand.Next(); string yaml = serializer.Serialize(test1); // %YAML 1.2 // --- // !YamlSerializerTest.Test1 // PublicProp: 0 // ReadOnlyClassProp: // Capacity: 4 // ICollection.Items: // - abc // ClassPropByContent: // Capacity: 0 // PublicField: 0 // IntArrayFieldBinary: |+2 // Gor1XAwenmhGkU5ib9NxR11LXxp1iYlH5LH4c9hImTitWSB9Z78II2UvXSXV99A79fj6UBn3GDzbIbd9 // yBDjAyslYm58iGd/NN+tVjuLRCg3cJBo+PWMbIWm9n4AEC0E7LKXWV5HXUNk7I13APEDWFMM/kWTz2EK // s7LzFw2gBjpKugkmQJqIfinpQ1J1yqhhz/XjA3TBxDBsEuwrD+SNevQSqEC+/KRbwgE6D011ACMeyRt0 // BOG6ZesRKCtL0YU6tSnLEpgKVBz+R300qD3/W0aZVk+1vHU+auzyGCGUaHCGd6dpRoEhXoIg2m3+AwJX // EJ37T+TA9BuEPJtyGoq+crQMFQtXj1Zriz3HFbReclLvDdVpZlcOHPga/3+3Y509EHZ7UyT7H1xGeJxn // eXPrDDb0Ul04MfZb4UYREOfR3HNzNTUYGRsIPUvHOEW7AaoplIfkVQp19DvGBrBqlP2TZ9atlWUHVdth // 7lIBeIh0wiXxoOpCbQ7qVP9GkioQUrMkOcAJaad3exyZaOsXxznFCA== // ... Assert.AreEqual( BuildResult( "!YamlSerializerTest.Test1", "IntArrayField: [0, 0, 0, 0, 0, 0, 0, 0, 0, 0]", "PublicField: 2", "IntArrayFieldBinary: |+2", " Gor1XAwenmhGkU5ib9NxR11LXxp1iYlH5LH4c9hImTitWSB9Z78II2UvXSXV99A79fj6UBn3GDzbIbd9", " yBDjAyslYm58iGd/NN+tVjuLRCg3cJBo+PWMbIWm9n4AEC0E7LKXWV5HXUNk7I13APEDWFMM/kWTz2EK", " s7LzFw2gBjpKugkmQJqIfinpQ1J1yqhhz/XjA3TBxDBsEuwrD+SNevQSqEC+/KRbwgE6D011ACMeyRt0", " BOG6ZesRKCtL0YU6tSnLEpgKVBz+R300qD3/W0aZVk+1vHU+auzyGCGUaHCGd6dpRoEhXoIg2m3+AwJX", " EJ37T+TA9BuEPJtyGoq+crQMFQtXj1Zriz3HFbReclLvDdVpZlcOHPga/3+3Y509EHZ7UyT7H1xGeJxn", " eXPrDDb0Ul04MfZb4UYREOfR3HNzNTUYGRsIPUvHOEW7AaoplIfkVQp19DvGBrBqlP2TZ9atlWUHVdth", " 7lIBeIh0wiXxoOpCbQ7qVP9GkioQUrMkOcAJaad3exyZaOsXxznFCA==", "ReadOnlyClassProp: ", " Capacity: 4", " ICollection.Items: ", " - def", "ClassPropByAssign: ", " Capacity: 4", " ICollection.Items: ", " - abc", "PublicProp: 3", "ClassPropByContent: ", " Capacity: 4", " ICollection.Items: ", " - ghi" ), yaml); object restored = serializer.Deserialize(yaml)[0]; Assert.AreEqual(test1.PublicField, ( (Test1)restored ).PublicField); Assert.AreEqual(test1.PublicProp, ( (Test1)restored ).PublicProp); Assert.AreEqual(test1.ReadOnlyClassProp, ( (Test1)restored ).ReadOnlyClassProp); Assert.AreEqual(test1.ClassPropByContent, ( (Test1)restored ).ClassPropByContent); Assert.AreEqual(test1.IntArrayFieldBinary, ( (Test1)restored ).IntArrayFieldBinary); }