티스토리 뷰
Generic Method 를 사용하면 상당히 유용한 Serialization 을 구사할 수 있다.
아래 예제는 Generic Method 를 사용하여 어떠한 Type이라도 쉽게 Serialize & Deserialize 할 수 있도록 한 것이다.
이런 것들은 실전에서 유용하게 이용될 수 있다.
using System;
using System.IO;
using System.Runtime.Serialization.Formatters.Binary;
namespace GenericSerializer
{
public static class Serializer
{
public static void Export<T>(string otherFile, T otherT)
{
using (Stream s = File.Open(otherFile, FileMode.Create))
{
BinaryFormatter bf = new BinaryFormatter();
bf.Serialize(s, otherT);
}
}
public static T Import<T>(string otherFile)
{
using (Stream s = File.Open(otherFile, FileMode.Open))
{
BinaryFormatter bf = new BinaryFormatter();
object o = bf.Deserialize(s);
T t = (T)o;
return t;
}
}
}
}
아래 예제는 Generic Method 를 사용하여 어떠한 Type이라도 쉽게 Serialize & Deserialize 할 수 있도록 한 것이다.
이런 것들은 실전에서 유용하게 이용될 수 있다.
using System;
using System.IO;
using System.Runtime.Serialization.Formatters.Binary;
namespace GenericSerializer
{
public static class Serializer
{
public static void Export<T>(string otherFile, T otherT)
{
using (Stream s = File.Open(otherFile, FileMode.Create))
{
BinaryFormatter bf = new BinaryFormatter();
bf.Serialize(s, otherT);
}
}
public static T Import<T>(string otherFile)
{
using (Stream s = File.Open(otherFile, FileMode.Open))
{
BinaryFormatter bf = new BinaryFormatter();
object o = bf.Deserialize(s);
T t = (T)o;
return t;
}
}
}
}
'Code > C#' 카테고리의 다른 글
실행중인 application의 path를 구하는 방법 (0) | 2007.12.15 |
---|---|
BinaryFormatter.Serialize 사용법 (0) | 2007.12.12 |
Serializable Attribute & BinaryFormatter 사용법 (0) | 2007.12.10 |
간단한 DataGridView 사용 예제 (0) | 2007.12.09 |
DateTime & TimeSpan : 두 시간 사이의 간격 계산하기 (0) | 2007.12.09 |
공지사항
최근에 올라온 글
최근에 달린 댓글
- Total
- Today
- Yesterday
링크
TAG
- Phalanger
- Regular Expressions
- 애드센스감추기
- WinAutomation
- Service pack
- windows
- AdSense감추기
- java
- 유틸리티
- AxWebBrowser
- READYSTATE_COMPLETE
- iTextSharp
- ScreenHunter
- jre
- tagREADYSTATE
- c#
- 스크린캡쳐
- autohotkey
- Sample Code
- Automation
- .net framework
- DotNetMagic
- iText
- download.com
- Rollback Rx
- AdSense숨기기
- Microsoft
- 애드센스숨기기
- registry
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | 4 | 5 | ||
6 | 7 | 8 | 9 | 10 | 11 | 12 |
13 | 14 | 15 | 16 | 17 | 18 | 19 |
20 | 21 | 22 | 23 | 24 | 25 | 26 |
27 | 28 | 29 | 30 | 31 |
글 보관함