// obj must be of type Table.Type, value of type Type public void Set(IDBObject obj, object value) { if (obj.GetType() != container.Type) { throw new ArgumentException("Attempt to set field " + this + " on object of type " + obj.GetType().FullName); } property.SetValue(obj, value, null); }
// obj must be of type Table.Type public object Get(IDBObject obj) { if (obj.GetType() != container.Type) { throw new ArgumentException("Attempt to get field " + this + " on object of type " + obj.GetType().FullName); } return(property.GetValue(obj, null)); }
public static void ConsolePrint(this IDBObject obj) { var type = obj.GetType(); foreach (var property in type.GetProperties()) { Console.WriteLine("{0}: {1}", property.Name, property.GetValue(obj)); } }
public void BringElementToFront(IDBObject element) { if (element == null) return; int graphPrior = (int)Graph.GetAlgorithmObj(_KH_PANE_GRAPH_PRIOR); if (new Edge(new Vertex(),new Vertex()).GetType().Equals(element.GetType())) { Edge e = (Edge)element; e.SetAlgorithmObj(_KH_PANE_GRAPH_PRIOR, graphPrior); } if(new Vertex().GetType().Equals(element.GetType())){ Vertex e = (Vertex)element; graphPrior += 1; e.SetAlgorithmObj(_KH_PANE_GRAPH_PRIOR, graphPrior); foreach (Edge ei in e.IncomingEdges) { BringElementToFront(ei); } foreach (Edge eo in e.OutgoingEdges) { BringElementToFront(eo); } } }
IEFSerializable Add(IEFSerializable obj, GalacticObjectContext c, bool saveChanges = true) { IDBObject saveme = obj.GetDBObject(); //_getDBSet(saveme).Add(saveme); Type t = saveme.GetType(); //This could use a convenient workaround... if (t == typeof(DBPSystem)) { c.Systems.AddOrUpdate((DBPSystem)saveme); } else if (t == typeof(DBMoon)) { c.Moons.AddOrUpdate((DBMoon)saveme); } else if (t == typeof(DBPort)) { c.Ports.AddOrUpdate((DBPort)saveme); } else if (t == typeof(DBPlanet)) { c.Planets.AddOrUpdate((DBPlanet)saveme); } else if (t == typeof(DBColony)) { c.Colonies.AddOrUpdate((DBColony)saveme); } else if (t == typeof(DBShip) || t.IsSubclassOf(typeof(DBShip))) { c.Ships.AddOrUpdate((DBShip)saveme); } else if (t == typeof(DBPlayer) || t.IsSubclassOf(typeof(DBPlayer))) { c.Players.AddOrUpdate((DBPlayer)saveme); } else if (t == typeof(DBAccount) || t.IsSubclassOf(typeof(DBAccount))) { c.Accounts.AddOrUpdate((DBAccount)saveme); } else if (t == typeof(PlanetLayout) || t.IsSubclassOf(typeof(PlanetLayout))) { c.Layouts.AddOrUpdate((PlanetLayout)saveme); } else if (t == typeof(ShipStats) || t.IsSubclassOf(typeof(ShipStats))) { c.ShipStats.AddOrUpdate((ShipStats)saveme); } else if (t == typeof(DBTeam)) { c.Teams.AddOrUpdate((DBTeam)saveme); } else if (t == typeof(StructureModel) || t.IsSubclassOf(typeof(StructureModel))) { c.Structures.Add((StructureModel)saveme); } else { throw new Exception("Error: Entity set not available for objects of type " + t.ToString()); } if (saveChanges) { c.SaveChanges(); } return(obj); }