Microsoft MVP성태의 닷넷 이야기
.NET : 36. Dictionary<,> 개체 직렬화 [링크 복사], [링크+제목 복사]
조회: 9575
글쓴 사람
정성태 (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)
145정성태5/6/20087047.NET : 30. XML Serializable Dictionary
144정성태3/28/20087670.NET : 29. WPF 응용 프로그램 - 웹캠으로 입력되는 스트림을 WMV 로 출력
143정성태3/28/20087964레지스트리 : 8. VHD 파일을 하드 디스크로 인식
142정성태3/26/20087293레지스트리 : 7. 아웃룩 2007의 제한된 첨부 파일을 허용하도록 설정
141정성태3/25/20087190레지스트리 : 6. 웹 브라우저(IE 8) 컨트롤 렌더링 모드 지정
140정성태2/23/20086598.NET : 28. 프로세스를 실행시켜주는 간단한 NT 서비스 제작 [1]
139정성태2/22/20085809.NET : 27. P/Invoke 를 이용한 메시지 서명 및 확인
138정성태2/21/20087332SMTP Commands
137정성태2/19/20085986.NET 3.5 : 5. LINQ to XML : Creating XML from another XML
136정성태2/1/20088113Win32 : 3. 사용자 개입없이 인증서 설치하는 코드 [2]
135정성태1/30/20085683COM : 5. Starting a Hyper-V Virtual Machine [3]
134정성태1/28/20085852Win32 : 2. How to generate key pairs, encrypt and decrypt data with CryptoAPI
133정성태1/16/20085921유틸리티 : 1. Writing Debugger extension program in C#
132정성태1/15/20086142VS.NET Addin - DB 연결 개체 추가
131정성태1/11/20086028기타 : 1. Maze Generator in C#
130정성태1/8/20086139VS.NET Addin - 프로젝트 닫기
129정성태1/2/20085874웹폼 코딩 규약 : 2. 서버측 ViewState 저장소
128정성태12/31/20075368레지스트리 : 5. List of registry keys affecting IIS7 behavior
127정성태12/21/20076089.NET : 26. CreateProcessWithLogonW / CreateProcessAsUser API 사용
126정성태12/20/20075115Win32 : 1. SLDF_RUNAS_USER
125정성태12/14/20075443.NET : 25. InfoPath 사용자 컨트롤
124정성태11/25/20075139SQL : 2. SQL Server 2008 에서 소개하는 spatial 데이터 타입
123정성태11/20/200711820.NET : 24. C# WebCam 사용자 컨트롤
122정성태11/17/20076230COM : 4. 외부 SMTP 를 지정하여 메일 보내기
121정성태9/14/20074911.NET 3.5 : 4. Entity Framework 관련 링크 모음
120정성태9/14/20074735Vista : 7. Gadget Samples for Windows Sidebar
1  2  [3]  4  5  6  7  8