Hello all...
Im doing some work with Graph, so create some clases:
Node Arc Graph.
(A Graph is a list of Nodes)
I like the idea about been able to save/load a graph to/from disk. Im trying to XmlSerialize my graph.
I have define my graph so, that this cannot be made, becouse: 1.- Node = { X, Y, ListOfOutgoingArcs } 2.- Arc = { StartNode, StopNode, Weight}
This definition is circular....
What do u think is the best to modify, for let the graph been saved to disk?
When i run this, i get this:
<mono1.0.5>
System.InvalidOperationException: A cirtular reference was detected while serializing an object of type Node
</mono>
thanks in advance,
--
_________________________ Phillip Neumann [EMAIL PROTECTED]
using System; using System.Xml; using System.Xml.Serialization; using System.Collections;
[Serializable, XmlInclude(typeof(Arc))] public class Node{ public ArrayList OutGoingArcs = new ArrayList(); public int X; public int Y; public Node(){} public Node(int x,int y){ X=x; Y=y; } } public class Arc{ public int Weight; public Node StartAt; public Node EndAt; public Arc(){} public Arc(Node n1, Node n2){ StartAt=n1; EndAt = n2; n1.OutGoingArcs.Add(this); } } [Serializable, XmlInclude(typeof(Node))] public class Graf{ public ArrayList Nodes; public Graf (){ Nodes = new ArrayList(); } public void Add(Node n){ Nodes.Add(n); } } public class M{ public static void Main(){ Graf g = new Graf(); Node n1 = new Node(1,1); Node n2 = new Node(2,2); Arc a1=new Arc(n1,n2); g.Add(n1); g.Add(n2); XmlSerializer seria = new XmlSerializer(typeof(Graf)); seria.Serialize(Console.Out,g); } }
begin:vcard fn:Phillip Neumann n:Neumann;Phillip email;internet:[EMAIL PROTECTED] tel;cell:09-2750469 x-mozilla-html:TRUE version:2.1 end:vcard