Veikedo

Untitled

Mar 19th, 2020
230
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.98 KB | None | 0 0
  1.   class Program
  2.   {
  3.     // тестовый пример по десериализации через ExtendedXmlSerializer
  4.     static void Main()
  5.     {
  6.       string executableLocation = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
  7.       string path = Path.Combine(executableLocation, "test.xml");
  8.  
  9.       using var fs = new FileStream(path, FileMode.Open);
  10.      
  11.       IExtendedXmlSerializer extendedXmlSerializer = new ConfigurationContainer()
  12.         .UseAutoFormatting()
  13.         .UseOptimizedNamespaces()
  14.         .EnableImplicitTyping(typeof(CarCollection))
  15.         .Create();
  16.  
  17. ;
  18.      
  19.       XmlSerializer standartSerializer = new XmlSerializer(typeof(CarCollection));
  20.  
  21.       // стандартный сериализатор работает, расширенный нет
  22.       var cars1 = standartSerializer.Deserialize(fs);
  23.      
  24.       fs.Seek(0, SeekOrigin.Begin);
  25.       var cars2 = extendedXmlSerializer.Deserialize<CarCollection>(fs);
  26.     }
  27.   }
Advertisement
Add Comment
Please, Sign In to add comment