Microsoft MVP성태의 닷넷 이야기
.NET : 36. Dictionary<,> 개체 직렬화 [링크 복사], [링크+제목 복사]
조회: 9577
글쓴 사람
정성태 (techsharer at outlook.com)
홈페이지
첨부 파일
 

Dictionary<,> 개체 직렬화


Post #7 ? Serializing Dictionary to/from XML
; http://blogs.msdn.com/mglehman/archive/2009/11/09/post-7-serializing-dictionary-string-string-to-from-xml.aspx

오호... Dictionary<,> 타입이 XmlSerializer 에서는 예외가 나더니만, DataContractSerializer 로는 직렬화가 잘 되는군요.

코드가 간단하니 아래에 실어봅니다.

static void Main(string[] args)
{
    Dictionary<string, string> dict = new Dictionary<string, string>();

    dict.Add("test", "test1");

    MemoryStream ms = new MemoryStream();
    XmlWriter writer = XmlWriter.Create(ms);

    // 예외 발생
    // XmlSerializer xs = new XmlSerializer(typeof(Dictionary<string, string>));
    // xs.Serialize(ms, dict);

    DataContractSerializer dcs = new DataContractSerializer(typeof(Dictionary<string, string>));
    dcs.WriteObject(writer, dict);
    writer.Close();

    ms.Position = 0;
    Dictionary<string, string> dict2 = dcs.ReadObject(ms) as Dictionary<string, string>;
}



[이 토픽에 대해서 여러분들과 의견을 공유하고 싶습니다. 틀리거나 미흡한 부분 또는 의문 사항이 있으시면 언제든 댓글 남겨주십시오.]







[최초 등록일: ]
[최종 수정일: 11/12/2009]

Creative Commons License
이 저작물은 크리에이티브 커먼즈 코리아 저작자표시-비영리-동일조건변경허락 2.0 대한민국 라이센스에 따라 이용하실 수 있습니다.

비밀번호

댓글 작성자
 




1  2  3  4  5  6  7  [8] 
NoWriterDateCnt.TitleFile(s)
18정성태7/17/20034009RegistryEx 클래스 (VC++6.0, Win32) 2000.02.28파일 다운로드1
17정성태9/22/20054870Crypto 클래스 (VC++6.0, Win32) [1]파일 다운로드1
16정성태7/17/20034426Win32 Control Spy (Win32)파일 다운로드1
15정성태7/17/20035107RichEdit Control 클래스 (VC ++ 6.0)파일 다운로드1
1  2  3  4  5  6  7  [8]