Class 를 던지면 해당 Class Property에 대하여 xml을 생성해주는 모듈
public static void CreateXml(object obj, string fileName)
{
try
{
Type typeofobj = obj.GetType();
XmlSerializer serializer = new XmlSerializer(typeofobj);
using (TextWriter writer = new StreamWriter(fileName))
{
serializer.Serialize(writer, obj);
writer.Close();
}
}
catch (Exception ex)
{
Console.WriteLine(ex);
}
}
//public static void CreateXml(List<object> obj, string fileName)
//{
// try
// {
// //LD.Log.Info("Excute CreateXml");
// Type typeofobj = obj.GetType();
// XmlSerializer serializer = new XmlSerializer(typeofobj);
// using (TextWriter writer = new StreamWriter(fileName))
// {
// serializer.Serialize(writer, obj);
// writer.Close();
// }
// }
// catch (Exception ex)
// {
// //LD.Log.Error("CreateXmlModView : " + ex.ToString());
// Console.WriteLine(ex);
// }
//}
public static object ReadXml(object obj, string strfileName)
{
try
{
Type typeofobj = obj.GetType();
XmlSerializer Deserializer = new XmlSerializer(typeofobj);
using (TextReader reader = new StreamReader(strfileName))
{
obj = Deserializer.Deserialize(reader);
return obj;
}
}
catch (Exception ex)
{
return obj;
}
}
public static object ReadXml(Type typeofobj, string strfileName)
{
try
{
XmlSerializer Deserializer = new XmlSerializer(typeofobj);
using (TextReader reader = new StreamReader(strfileName))
{
object obj = Deserializer.Deserialize(reader);
return obj;
}
}
catch (Exception ex)
{
return null;
}
}
'프로그래밍 > C#' 카테고리의 다른 글
OpenCVSharp (0) | 2014.10.23 |
---|---|
클래스 리스트 ..아니 오브젝트 리스트?.. (0) | 2013.07.23 |
Microsoft SQL Server 2012 Express (0) | 2013.07.15 |
Pinvokestackimbalance was detected (0) | 2013.06.04 |
C# Datagridview Data를 Directx3D로..표현해보았다.. (0) | 2013.04.12 |