Microsoft MVP성태의 닷넷 이야기
.NET : 36. Dictionary<,> 개체 직렬화 [링크 복사], [링크+제목 복사]
조회: 9537
글쓴 사람
정성태 (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)
197정성태7/30/20211479.NET : 63. Spectre.Console
196정성태10/28/20193153장치 관리자처럼 각 장치들에 할당된 리소스(예: Memory Range) 상태를 코드로 알아내는 방법
195정성태4/25/20192962Extracting Text from an Image Using Tesseract in C#
194정성태4/25/20192715Parse the Command Line with System.CommandLine
193정성태8/2/20175601.NET : 62. github - C# to JavaScript, WPF to JavaScript and Samples
192정성태6/29/20165145.NET : 61. TreeLib: Balanced Binary Trees ? Rank Augmented, for .NET
191정성태10/13/20156348.NET : 60. MICROSOFT TRANSLATOR HUB
190정성태6/20/20157061Win32 : 6. UMDH Visualizer - Memory profile viewer
189정성태1/19/20148675.NET : 59. QR 코드를 ASP.NET과 WPF에서 사용하는 방법
188정성태1/15/20148873.NET : 58. 윈도우폰 7 - 안면인식, Cartooning...
187정성태1/14/20148808.NET : 57. BCL에서 제공되는 컬렉션에 만족하지 못한다면? [1]
186정성태6/26/20138756.NET : 56. The managed way to retrieve text under the cursor (mouse pointer)
185정성태9/27/20129627.NET : 55. Face Detection with Emgu CV in C# and WPF
184정성태9/23/20128463.NET : 54. What was that sound Visual Studio? Audio Editor Beta For VS 2012 (plus free sounds library too!)
183정성태4/19/201210224.NET : 53. Virtual Router 소스 코드 및 실행 파일 (C#)
182정성태4/16/201210803.NET : 52. SharpDX [1]
181정성태3/3/201214121.NET : 51. .NET에서 DirectX를 이용하여 스크린 캡쳐를 빠르게 하는 방법 [3]
180정성태3/3/20129301.NET : 50. Restart Manager 를 이용하여 .NET 에서 잠긴 파일을 소유하고 있는 프로세스 찾는 방법
179정성태1/14/20128624.NET : 49. WebAPI Developer Preview 6: Self Hosted Mode Example
178정성태10/31/201110699.NET : 48. app.config의 supportedRuntime 예시
177정성태10/15/20119600.NET : 47. Irony - Language Implementation Kit
176정성태7/22/20119527.NET : 46. Manual Validation with Data Annotations
175정성태5/18/201111269Win32 : 5. UuidCreateSequential
174정성태5/4/20119744.NET : 45. NTrace v2 now available (think Managed VS2010/.Net 4 Event Tracing for Windows)
173정성태4/12/201111170레지스트리 : 11. BHO를 IE와 탐색기에서 선택적으로 로드하고 싶다면?
[1]  2  3  4  5  6  7  8