private static Dictionary <String, DelayGraphVertex> RecreateVertices(XElement graph, String nmsp, DelayGraph delayGraph) { var nodeIdToVertexMap = new Dictionary <String, DelayGraphVertex>(); var vertexType = typeof(DelayGraphVertex); // todo: update this map if new properties are added...or use "CreatePropertyTypeMap" below var propertyToTypeMap = new Dictionary <String, Type>() { { "VertexId", typeof(int) }, { "NodeType", typeof(int) }, { "NodeUniqueId", typeof(int) }, { "ThroughputCostIfRegistered", typeof(long) }, { "LatencyCostIfRegistered", typeof(long) }, { "RegisterCostIfRegistered", typeof(long) }, { "IsRegistered", typeof(bool) }, { "IsInputTerminal", typeof(bool) }, { "IsOutputTerminal", typeof(bool) }, { "DisallowRegister", typeof(bool) } }; // get the nodes foreach (var node in graph.Elements(nmsp + "node")) { // create new vertex var vertex = new DelayGraphVertex(); var id = (string)node.Attribute("id"); nodeIdToVertexMap.Add(id, vertex); // populate the fields of the node foreach (var data in node.Elements()) { var key = (string)data.Attribute("key"); dynamic contents = Convert.ChangeType(data.Value, propertyToTypeMap[key], CultureInfo.InvariantCulture); vertexType.GetProperty(key).SetValue(vertex, contents); } // add the node to the graph delayGraph.AddVertex(vertex); } return(nodeIdToVertexMap); }