Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <Query Kind="Program">
- <NuGetReference>Jil</NuGetReference>
- <Namespace>Jil</Namespace>
- <Namespace>System.Runtime.Serialization</Namespace>
- </Query>
- void Main()
- {
- var objs = new List<MyBaseClass>();
- objs.Add(new MySubClass(new [] { "foo", "bar", 3.0f.ToString() }));
- objs.Add(new MySubClass(new [] { "foo", "bar", 3.0f.ToString() }));
- objs.Add(new MySubClass(new [] { "foo", "bar", 3.0f.ToString() }));
- using (var output = new StringWriter())
- {
- JSON.Serialize(
- objs,
- output,
- Options.ISO8601IncludeInherited
- );
- output.ToString().Dump(); // this prints [{},{},{}]
- }
- }
- // Define other methods and classes here
- public class MyBaseClass
- {
- [DataMember]
- string FileName { get; set; }
- [DataMember]
- string FileCreationTime { get; set; }
- public MyBaseClass(string[] rawRecord)
- {
- this.FileName = rawRecord[0];
- this.FileCreationTime = rawRecord[1];
- }
- }
- public class MySubClass : MyBaseClass
- {
- [DataMember]
- float X;
- public MySubClass(string[] rawRecord) : base(rawRecord)
- {
- this.X = float.Parse(rawRecord[2]);
- }
- }
Add Comment
Please, Sign In to add comment