Link to home
Start Free TrialLog in
Avatar of peter3244
peter3244Flag for United Kingdom of Great Britain and Northern Ireland

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></ruletype>
     </condition>
     <condition>
           <control>asdfasd</control>
            <ruletype>Mdfdfgdfg></ruletype>
     </condition>
     <condition>
           <control>asdfasd</control>
            <ruletype>Mdfdfgdfg></ruletype>
     </condition>
     <condition>
           <control>asdfasd</control>
            <ruletype>Mdfdfgdfg></ruletype>
     </condition>
</Conditons>
Avatar of redpipe
redpipe
Flag of Norway image

You can do this by declaring the class as Serializable and create a helper that does the XML serialization and deserialization. Look at this sample:
http://www.jonasjohn.de/snippets/csharp/xmlserializer-example.htm
ASKER CERTIFIED SOLUTION
Avatar of KinjalKumar Patel
KinjalKumar Patel

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of peter3244

ASKER

H

{"Cannot serialize member WindowsApplication1.Condition.Conditions of type System.Collections.Generic.Dictionary`2[[System.Int32, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089],[WindowsApplication1.Condition, WindowsApplication1, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null]], because it implements IDictionary."}
Sorry. I get the error

{"Cannot serialize member WindowsApplication1.Condition.Conditions of type System.Collections.Generic.Dictionary`2[[System.Int32, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089],[WindowsApplication1.Condition, WindowsApplication1, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null]], because it implements IDictionary."}

Any I ideas
I thought it was [Serializable()] at the top not [Serializable].
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Thanks guys the mistake was mine