Iyon_Groznyy

Untitled

Oct 16th, 2020
238
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 3.69 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.IO;
  4. using System.Linq;
  5. using System.Runtime.Serialization.Formatters.Binary;
  6.  
  7. namespace Test
  8. {
  9.     class Program
  10.     {
  11.         static void Main(string[] args)
  12.         {
  13.             #region рефлексия
  14.             //A firstObj = new A() { count = 10, lst = new List<string>() { "asdasd", "asd123as123sd" } };
  15.             //A secondObj = new A();
  16.             //List<object> s = firstObj.GetType().GetFields().Select(x => x.GetValue(firstObj)).ToList();
  17.             //int i = 0;
  18.             //foreach (var fd in secondObj.GetType().GetFields())
  19.             //{
  20.             //    fd.SetValue(secondObj, s[i]);
  21.             //    i++;
  22.             //}
  23.             #endregion
  24.             List<A> aa = new List<A>();
  25.             List<B> bb = new List<B>();
  26.             for (int i = 0; i < 10000; i++)
  27.             {
  28.                 aa.Add(new A());
  29.                 bb.Add(new B());
  30.             }
  31.             using (Stream stream = new MemoryStream())
  32.             {
  33.                 BinaryFormatter formatter = new BinaryFormatter();
  34.                 formatter.Serialize(stream, aa);
  35.                 Console.WriteLine("С int " + stream.Length);
  36.             }
  37.             using (Stream stream = new MemoryStream())
  38.             {
  39.                 BinaryFormatter formatter = new BinaryFormatter();
  40.                 formatter.Serialize(stream, bb);
  41.                 Console.WriteLine("С byte " + stream.Length);
  42.             }
  43.  
  44.  
  45.         }
  46.     }
  47.     [Serializable]
  48.     class A
  49.     {
  50.         public ReportType reportType = ReportType.REPORT_FILE_SA;
  51.     }
  52.     [Serializable]
  53.     class B
  54.     {
  55.         public ReportTypeB reportType = ReportTypeB.REPORT_FILE_SA;
  56.     }
  57.     public enum ReportType      // Can we remove this enumerator due to its unused in class?
  58.     {
  59.         /// <summary>
  60.         /// report will be saved as file with static analysis results
  61.         /// </summary>
  62.         REPORT_FILE_SA,
  63.         /// <summary>
  64.         /// report will be saved as file with no static analysis results
  65.         /// </summary>
  66.         REPORT_FILE_NOSA,
  67.         /// <summary>
  68.         /// report will be displayed as table with static analysis results
  69.         /// </summary>
  70.         REPORT_TABLE_SA,
  71.         /// <summary>
  72.         /// report will be displayed as table with no static analysis results
  73.         /// </summary>
  74.         REPORT_TABLE_NOSA,
  75.         /// <summary>
  76.         /// report will be displayed as tree with static analysis results
  77.         /// </summary>
  78.         REPORT_TREE_SA,
  79.         /// <summary>
  80.         /// report will be displayed as tree with no static analysis results
  81.         /// </summary>
  82.         REPORT_TREE_NOSA
  83.     }
  84.     public enum ReportTypeB : byte      // Can we remove this enumerator due to its unused in class?
  85.     {
  86.         /// <summary>
  87.         /// report will be saved as file with static analysis results
  88.         /// </summary>
  89.         REPORT_FILE_SA,
  90.         /// <summary>
  91.         /// report will be saved as file with no static analysis results
  92.         /// </summary>
  93.         REPORT_FILE_NOSA,
  94.         /// <summary>
  95.         /// report will be displayed as table with static analysis results
  96.         /// </summary>
  97.         REPORT_TABLE_SA,
  98.         /// <summary>
  99.         /// report will be displayed as table with no static analysis results
  100.         /// </summary>
  101.         REPORT_TABLE_NOSA,
  102.         /// <summary>
  103.         /// report will be displayed as tree with static analysis results
  104.         /// </summary>
  105.         REPORT_TREE_SA,
  106.         /// <summary>
  107.         /// report will be displayed as tree with no static analysis results
  108.         /// </summary>
  109.         REPORT_TREE_NOSA
  110.     }
  111. }
Advertisement
Add Comment
Please, Sign In to add comment