Generic Dictionary는 Xml.Serialization.XmlSerializer을 사용해서 serialize할 수 없다. 그래서 Generic Dictionary을 XML 파일로 serialize할 수 있는 GenericDictionaryXmlSerializer 클래스를 만들어 보았다. 이 클래스는 아래 링크에 있는 코드를 응용해서 만든 것이다. http://blogs.msdn.com/psheill/archive/2005/04/09/406823.aspx 위의 링크에 있는 코드는 Generic 클래스를 사용하지 않았는데, 필자의 코드는 Generic 코드를 사용한 점이 다르다. using System; using System.Collections.Generic; using System.Xml;..
Xml.Serialization 을 이용해서 DateTime 멤버를 포함하고 있는 객체의 Serialization을 시도해보았다. 결과는 만족스러웠다. 아무런 문제 없이 Serialization이 잘 이루어졌다. 아래는 예제 코드이다. 아래에서 Chrono 클래스는 string field 와 DateTime field를 가지고 있다. using System; using System.Collections.Generic; using System.Xml; using System.Xml.Serialization; namespace SerializationTest { class Program { static void Main(string[] args) { Chrono c1 = new Chrono(); Chrono..
List 객체도 XML Serialization이 가능하다. 아래는 그 예제이다. 별로 어렵지 않은 예제이니 잘 살펴보기 바란다. using System; using System.Collections.Generic; using System.Xml; using System.Xml.Serialization; namespace SerializationTest { class Program { static void Main(string[] args) { List myList = new List(); myList.Add("One"); myList.Add("Two"); myList.Add("Three"); XmlSerializer myXmlSerializer = new XmlSerializer(typeof(List)..
Xml.Serialization 을 사용하면 XML 형식으로 Serialization 할 수 있다. 아래 예제를 보자. 아래 예제는 string 객체를 Serialization 한 예제이다. XmlSerializer 와 XmlWriter, XmlReader 를 사용해서 Serialize & Deserialize 한다. using System; using System.Xml; using System.Xml.Serialization; namespace SerializationTest { class Program { static void Main(string[] args) { string myName = "John Dow"; using (XmlWriter writer = XmlWriter.Create("ser..
현재 실행 중인 어플리케이션과 같은 폴더에 있는 파일이나, 하위 폴더에 있는 파일의 위치를 지정하고자 한다면, Path 클래스를 사용하면 된다. 아래는 간단한 예제이다. Application.ExecutablePath 은 현재 실행 중인 어플리케이션의 위치를 반환한다. Path.GetDirectoryName 은 path에서 폴더 값만 반환한다. Path.Combine 은 두개의 path를 결합한다. using System; using System.IO; using System.Windows.Forms; namespace WindowsFormsApplication1 { public partial class Form1 : Form { public Form1() { InitializeComponent(); }..
Windows Form Application의 path를 구하는 방법은 간단하다. Application.ExecutablePath 를 사용하면 된다. 아래는 사용 예제이다. using System; using System.Windows.Forms; namespace WindowsFormsApplication1 { public partial class Form1 : Form { public Form1() { InitializeComponent(); } private void button1_Click(object sender, EventArgs e) { this.textBox1.Text = Application.ExecutablePath; } } }
아래는 실행중인 어플리케이션의 현재 위치를 구하는 간단한 예제이다. 이 예제는 System.Reflection 을 사용했다. Assembly.GetExecutingAssembly() 은 현재의 Assembly를 반환한다. Location Property는 Assembly의 위치를 반환한다. using System; using System.Reflection; namespace Test { class Program { static void Main(string[] args) { string myPath = Assembly.GetExecutingAssembly().Location; Console.WriteLine(myPath); Console.Read(); } } }
BinaryFormatter.Serialize 와 BinaryFormatter.Deserialize 를 사용한 예제입니다. 아래 예제를 보면 [Serializable] Attribute를 사용한 Name 클래스만 Serialize & Deserialize 한 것을 알 수 있습니다. 이 예제는 사실 BinaryFormatter.Serialize & BinaryFormatter.Deserialize 의 버그 여부를 조사하기 위해서 만들었습니다. Serialize 후 일부 데이터를 변경하고, 다시 Deserialize 했을 때, 혹시 버그가 있나 검사해봤는데, 정상이었습니다. BinaryFormatter.Serialize & BinaryFormatter.Deserialize 는 generic static me..
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(string otherFile, T otherT) { using (Stream s = File.Open(..
객체를 serialize 하여 파일에 저장하는 방법은 아래와 같다. serialize 하려는 클래스에 [Serializable] Attribute 를 붙인다. Stream 으로 serialize 파일을 연다. BinaryFormatter.Serialize 로 serialize 된 객체를 파일에 저장한다. BinaryFormatter.Deserialize 를 사용하면 serialize 되어 파일에 저장된 객체를 불러올 수 있다. 아래 예제를 살펴보자. using System; using System.IO; using System.Runtime.Serialization.Formatters.Binary; namespace SerializableAttribute0001 { class Program { stati..
- Total
- Today
- Yesterday
- autohotkey
- ScreenHunter
- 유틸리티
- 애드센스감추기
- c#
- Regular Expressions
- AdSense숨기기
- Microsoft
- registry
- Sample Code
- jre
- download.com
- Phalanger
- Automation
- READYSTATE_COMPLETE
- WinAutomation
- AxWebBrowser
- iTextSharp
- DotNetMagic
- 스크린캡쳐
- .net framework
- tagREADYSTATE
- AdSense감추기
- iText
- 애드센스숨기기
- windows
- Service pack
- java
- Rollback Rx
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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 |