Example #1
0
        /// <summary> Из ребра в ДТО </summary>
        public static EdgeDto Convert(IEdge value)
        {
            Contract.Requires <ArgumentNullException>(value != null);

            return(new EdgeDto
            {
                Vertex1 = VertexToDtoConverter.Convert(value.Vertex1),
                Vertex2 = VertexToDtoConverter.Convert(value.Vertex2),
                Directed = value.Directed,
                Weight = (value is IWeightedEdge) ? ((IWeightedEdge)value).Weight : (int?)null
            });
        }
Example #2
0
        /// <summary> Из ДТО в граф </summary>
        public static IGraph ConvertBack(GraphDto value)
        {
            if (value.AllowMultipleEdges)
            {
                throw new InvalidOperationException("Данный тип графов не поддерживается.");
            }
            var graph = value.Directed
                            ? (
                !value.IsWeighted
                                      ? (IGraph) new DirectedGraph()
                                      : (IGraph) new DirectedWeightedGraph()
                )
                            : (IGraph) new UndirectedGraph();

            value.Vertices.ForEach(v => graph.AddVertex(VertexToDtoConverter.ConvertBack(v)));
            value.Edges.ForEach(e => graph.AddEdge(EdgeToDtoConverter.ConvertBack(e, graph.Vertices)));

            return(graph);
        }