Advertisement
Guest User

SerializationTest

a guest
Jan 25th, 2012
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.98 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Runtime.Serialization;
  6. using System.IO;
  7.  
  8. namespace SerializingTest
  9. {
  10.     class Program
  11.     {
  12.         static void Main(string[] args)
  13.         {
  14.             Brazier[] braziers = { new LinearBrazier() };
  15.  
  16.             var ser = new DataContractSerializer(typeof(Brazier[]));
  17.             using (var stream = new MemoryStream())
  18.             {
  19.                 ser.WriteObject(stream, braziers);
  20.                 Console.WriteLine(Encoding.ASCII.GetString(stream.ToArray()));
  21.             }
  22.  
  23.             Console.ReadKey();
  24.         }
  25.     }
  26.     [Serializable]
  27.     [KnownType("GetKnownType")]
  28.     public class Brazier
  29.     {
  30.         private static Type[] GetKnownType()
  31.         {
  32.             Type[] t = new Type[1];
  33.             t[0] = typeof(LinearBrazier);
  34.             return t;
  35.         }
  36.     }
  37.  
  38.  
  39.     [Serializable]
  40.     public class LinearBrazier : Brazier
  41.     {
  42.     }
  43. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement