Skip to content

Instantly share code, notes, and snippets.

@kevin-montrose
Created February 9, 2018 14:55
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save kevin-montrose/ee66d2789804b4440be537c38e75ce04 to your computer and use it in GitHub Desktop.
Q:48694886 repro
<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