Created
May 5, 2015 11:40
-
-
Save PureKrome/df7b5bdd6582cd99a98a to your computer and use it in GitHub Desktop.
Class is persisted with a $type property.
This file contains hidden or 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
using System; | |
using System.Collections.Generic; | |
using System.Linq; | |
using System.Text; | |
using System.Threading.Tasks; | |
using Raven.Client.Document; | |
namespace ConsoleApplication5 | |
{ | |
class Program | |
{ | |
private static IList<Person> FakePeople | |
{ | |
get | |
{ | |
var people = new List<Person> | |
{ | |
new Soldier | |
{ | |
Name = "Jane", | |
Equipment = new ReconEquipment | |
{ | |
CamoColour = "red", | |
FlareCount = 3 | |
} | |
}, | |
new Medic | |
{ | |
Name = "Joe", | |
Equipment = new HeavyWeaponsEquipment | |
{ | |
CamoColour = "blue", | |
SandvichCount = 2 | |
} | |
} | |
}; | |
return people; | |
} | |
} | |
static void Main(string[] args) | |
{ | |
var store = new DocumentStore | |
{ | |
Url = "http://localhost:8080/", | |
DefaultDatabase = "RhinoNinjas" | |
}; | |
store.Initialize(); | |
using (var session = store.OpenSession()) | |
{ | |
foreach (var person in FakePeople) | |
{ | |
session.Store(person); | |
} | |
session.SaveChanges(); | |
} | |
} | |
} | |
public class Soldier : BasePerson<ReconEquipment> | |
{ | |
} | |
public class Medic : BasePerson<HeavyWeaponsEquipment> | |
{ | |
} | |
public abstract class BasePerson<TEquipment> : Person where TEquipment : IEquipment | |
{ | |
public new TEquipment Equipment | |
{ | |
get { return (TEquipment)base.Equipment; } | |
set { base.Equipment = value; } | |
} | |
} | |
public abstract class Person | |
{ | |
public string Name { get; set; } | |
public IEquipment Equipment { get; set; } | |
} | |
public interface IEquipment | |
{ | |
string Name { get; } | |
string CamoColour { get; set; } | |
} | |
public class ReconEquipment : IEquipment | |
{ | |
public string Name { get { return "Recon"; } } | |
public string CamoColour { get; set; } | |
public int FlareCount { get; set; } | |
} | |
public class HeavyWeaponsEquipment : IEquipment | |
{ | |
public string Name { get { return "Heavy Metal"; } } | |
public string CamoColour { get; set; } | |
public int SandvichCount { get; set; } | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment