참고 : Serialize을 할때 setter 속성이 없는 경우 Serialize가 되지 않는다.
XmlSerialize>>
using System;
using System.IO;
using System.Xml.Serialization;
namespace API.Hello.Serialize
{
public class XmlSerialize
{
private static XmlSerialize _instance;
public string ToSerialize(object o)
{
XmlSerializer xs = null;
StringWriter sw = null;
try
{
xs = new XmlSerializer(o.GetType());
using (sw = new StringWriter())
{
xs.Serialize(sw, o);
return sw.ToString();
}
}
catch (Exception ex)
{
return ex.Message;
}
finally
{
if (xs != null)
xs = null;
if(sw !=null)
{
sw.Dispose();
sw = null;
}
}
}
public static XmlSerialize Instance
{
get
{
if(_instance == null)
{
_instance = new XmlSerialize();
}
return _instance;
}
}
}
}
API.DB.Hello.Table.Model>>
using System;
using System.Xml.Serialization;
namespace API.DB.Hello.Table.Model
{
[Serializable()]
public class HelloModel
{
private int key = 0;
private string data = null;
private string data1 = null;
[XmlElement("Key", IsNullable = false)]
public int Key { get { return key; } set { key = value; } }
[XmlElement("Data")]
public string Data { get { return data; } set { data = value; } }
[XmlElement("Data1")]
public string Data1 { get { return data1;} set { data1 = value; } }
}
}
'개발관련 > C#' 카테고리의 다른 글
ObjectSerialize (0) | 2017.08.10 |
---|---|
Aes 암호화/복호화 (0) | 2017.08.10 |
모든 타입 xmlWriter (0) | 2017.08.10 |
Http Handler 비동기 처리 (0) | 2017.07.25 |
구글 billing 영수증 검증 토큰 얻기 (4) | 2017.06.28 |