示例#1
0
        static void Main(string[] args)
        {
            //BookA book = new BookA();
            //book.title = "Serialization Overview";
            //book.Author = new AuthorA();
            //book.Author.Name = "홍길동";
            //book.Author.Country = "Korea";

            // Xml Serialize
            //SerializationDemo.XmlSerialize(book);
            // Xml Deserialize
            //var fromXml = SerializationDemo.XmlDeserialize();

            //Binary Serialize
            //SerializationDemo.BinarySerialize(book);
            // Binary Deserialize
            //var fromBinary = SerializationDemo.BinaryDeSerialize();

            //List<GraphItem> items = new List<GraphItem>();
            //for(int i=0; i < 100000; i++)
            //{
            //	var item = new GraphItem();
            //	item.C1 = 1.3f;
            //	item.C2 = 1.44f;
            //	items.Add(item);
            //}

            //GraphItem.DataContractSerializ(items, "d:\\testFile2.bin");

            var kk = GraphItem.DataContractDeserialize("d:\\testFile2.bin");
            var xx = kk;

            var Bs = new List<BookA>();

            var xxx = Bs.Where(b => b.Author.Name == "John").First();

            var book = new BookA();
            var au = book.Author;
            var books = book.Author.Books.Where(b => b.title == "Hello").Select(b => new { id = b.Author });
        }
示例#2
0
 public static void XmlSerialize(BookA book)
 {
     System.Xml.Serialization.XmlSerializer writer = new System.Xml.Serialization.XmlSerializer(typeof(BookA));
     System.IO.StreamWriter file = new System.IO.StreamWriter(@"d:\bookInfo.xml");
     writer.Serialize(file, book);
     file.Close();
 }
示例#3
0
 public static void BinarySerialize(BookA book)
 {
     IFormatter formatter = new BinaryFormatter();
     Stream stream = new FileStream(@"d:\bookData.bin", FileMode.Create, FileAccess.Write, FileShare.None);
     formatter.Serialize(stream, book);
     stream.Close();
 }