public static void ClearIfEmpty(this PropertyGraphModel model) { model.Vertices = model.Vertices?.Count > 0 ? model.Vertices : null; model.Edges = model.Edges?.Count > 0 ? model.Edges : null; if (model.Vertices != null) { foreach (var vertex in model.Vertices) { if (vertex.Props != null && vertex.Props.Count == 0) { vertex.Props = null; } } } if (model.Edges != null) { foreach (var edge in model.Edges) { if (edge.Props != null && edge.Props.Count == 0) { edge.Props = null; } } } }
public static PropertyGraphModel DeepCopy(this PropertyGraphModel model) { var result = new PropertyGraphModel(); if (model.Vertices != null) { result.Vertices = model.Vertices.Select(DeepCopy).ToList(); } if (model.Edges != null) { result.Edges = model.Edges.Select(DeepCopy).ToList(); } result.CreateLinks(); result.CreateIndex(); return(result); }
public static void CreateLinks(this PropertyGraphModel model) { if (model.Vertices == null || model.Edges == null) { return; } foreach (var vertex in model.Vertices) { vertex.Edges = new List <PropertyEdgeModel>(); } foreach (var edge in model.Edges) { var source = model.Vertices[edge.Source]; var target = model.Vertices[edge.Target]; edge.SourceVertex = source; edge.TargetVertex = target; source.Edges.Add(edge); target.Edges.Add(edge); } }