Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class Foo {
- public List<Tuple<string, string, bool>> Items { get; set; }
- public Foo()
- {
- Items = new List<Tuple<string, string, bool>>();
- }
- public override string ToString()
- {
- StringBuilder sb = new StringBuilder();
- foreach (var a in Items)
- {
- sb.Append(a.Item1 + ", " + a.Item2 + ", " + a.Item3.ToString() + "rn");
- }
- return sb.ToString();
- }
- }
- [TestClass]
- public class NormalTests
- {
- [TestMethod]
- public void TupleSerialization()
- {
- Foo tests = new Foo();
- tests.Items.Add(Tuple.Create("one", "hehe", true));
- tests.Items.Add(Tuple.Create("two", "hoho", false));
- tests.Items.Add(Tuple.Create("three", "ohoh", true));
- string json = JsonConvert.SerializeObject(tests);
- Console.WriteLine(json);
- var obj = JsonConvert.DeserializeObject<Foo>(json);
- string objStr = obj.ToString();
- Console.WriteLine(objStr);
- }
- }
- var testTuple = Tuple.Create(1234, "foo", true);
- var serialized = JsonConvert.SerializeObject(testTuple);
- Console.WriteLine(serialized);
- // prints: {"Item1":1234,"Item2":"foo","Item3":true}
Add Comment
Please, Sign In to add comment