Hi everybody, please help. I have this code, it's my class to serialize\deserialize application settings.
public static MyConfigClass myConfigClass = new MyConfigClass();
private static String myConfigFileName = AppDomain.CurrentDomain.BaseDirectory + "\\ApplicationConfig.xml";
[XmlRoot("EvaStartupData")]
[Serializable]
public class MyConfigClass
{
public string ServerName { get; set; }
public string Database { get; set; }
public string UserName { get; set; }
public string UserLogin { get; set; }
public static void MyConfigLoad()
{
FileInfo fi = new FileInfo(myConfigFileName);
if (fi.Exists)
{
XmlSerializer mySerializer = new XmlSerializer(myConfigClass.GetType());
StreamReader myXmlReader = new StreamReader(myConfigFileName);
try
{
myConfigClass = (MyConfigClass)mySerializer.Deserialize(myXmlReader);
myXmlReader.Close();
}
catch (Exception e)
{
MessageBox.Show("Ошибка сериализации MyConfigLoad\n" + e.Message);
}
finally
{
myXmlReader.Dispose();
}
}
}
public static void MyConfigSave()
{
XmlSerializer mySerializer = new XmlSerializer(myConfigClass.GetType());
StreamWriter myXmlWriter = new StreamWriter(myConfigFileName);
try
{
mySerializer.Serialize(myXmlWriter, myConfigClass);
}
catch (Exception e)
{
MessageBox.Show("Ошибка сериализации MyConfigSave\n" + e.Message);
}
finally
{
myXmlWriter.Dispose();
}
}
}
Serialization give's me simple xml-structure:
<ServerName>navuhodonoser</ServerName>
<Database>matrix</Database>
<UserName>Mr.Smith</UserName>
<UserLogin>neo</UserLogin>
How must i modify my class to get this xml structure ?:
<Connection ServerName="navuhodonoser" Database="matrix" ....>