Created
February 9, 2018 14:55
Star
You must be signed in to star a gist
Q:48694886 repro
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<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]); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment