peter3244
asked on
I have a class which i need to serialise in C#
Hi I need to serailise a class to produce XML. xsd.exe produces code that I can't understand. Could some please do a simple example based on the code below:
public class Condition
{
Dictionary<string, Condtion> _conditions = new <string, Condtion>
private string _control = string.Empty;
public string Control
{
get { return _control; }
set { _control = value; }
}
private string _ruleType = string.Empty;
public string _ruleType
{
get { return _ruleType; }
set { _ruleType = value; }
}
the xml i need is allong the lines of
<Conditons>
<condition>
<control>asdfasd</control>
<ruletype>Mdfdfgdfg></rule type>
</condition>
<condition>
<control>asdfasd</control>
<ruletype>Mdfdfgdfg></rule type>
</condition>
<condition>
<control>asdfasd</control>
<ruletype>Mdfdfgdfg></rule type>
</condition>
<condition>
<control>asdfasd</control>
<ruletype>Mdfdfgdfg></rule type>
</condition>
</Conditons>
public class Condition
{
Dictionary<string, Condtion> _conditions = new <string, Condtion>
private string _control = string.Empty;
public string Control
{
get { return _control; }
set { _control = value; }
}
private string _ruleType = string.Empty;
public string _ruleType
{
get { return _ruleType; }
set { _ruleType = value; }
}
the xml i need is allong the lines of
<Conditons>
<condition>
<control>asdfasd</control>
<ruletype>Mdfdfgdfg></rule
</condition>
<condition>
<control>asdfasd</control>
<ruletype>Mdfdfgdfg></rule
</condition>
<condition>
<control>asdfasd</control>
<ruletype>Mdfdfgdfg></rule
</condition>
<condition>
<control>asdfasd</control>
<ruletype>Mdfdfgdfg></rule
</condition>
</Conditons>
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
H
{"Cannot serialize member WindowsApplication1.Condit ion.Condit ions of type System.Collections.Generic .Dictionar y`2[[Syste m.Int32, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c56193 4e089],[Wi ndowsAppli cation1.Co ndition, WindowsApplication1, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null]], because it implements IDictionary."}
{"Cannot serialize member WindowsApplication1.Condit
ASKER
Sorry. I get the error
{"Cannot serialize member WindowsApplication1.Condit ion.Condit ions of type System.Collections.Generic .Dictionar y`2[[Syste m.Int32, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c56193 4e089],[Wi ndowsAppli cation1.Co ndition, WindowsApplication1, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null]], because it implements IDictionary."}
Any I ideas
{"Cannot serialize member WindowsApplication1.Condit
Any I ideas
I thought it was [Serializable()] at the top not [Serializable].
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thanks guys the mistake was mine
http://www.jonasjohn.de/snippets/csharp/xmlserializer-example.htm