Advertisement
Guest User

Immutable List

a guest
Jun 25th, 2016
195
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.37 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Reflection;
  5.  
  6. namespace ImmutableList
  7. {
  8.     public class ImmutableListMain
  9.     {
  10.         public static void Main()
  11.         {
  12.             Type immutableList = typeof(ImmutableList);
  13.             FieldInfo[] fields = immutableList.GetFields();
  14.             if (fields.Length < 1)
  15.             {
  16.                 throw new Exception();
  17.             }
  18.             else
  19.             {
  20.                 Console.WriteLine(fields.Length);
  21.             }
  22.  
  23.             MethodInfo[] methods = immutableList.GetMethods();
  24.             bool containsMethod = methods.Any(m => m.ReturnType.Name.Equals("ImmutableList"));
  25.             if (!containsMethod)
  26.             {
  27.                 throw new Exception();
  28.             }
  29.             else
  30.             {
  31.                 Console.WriteLine(methods.Length);
  32.             }
  33.         }
  34.     }
  35.  
  36.     public class ImmutableList
  37.     {
  38.         public List<int> integers;
  39.  
  40.         public ImmutableList(List<int> integers)
  41.         {
  42.             this.integers = integers;
  43.         }
  44.  
  45.         public ImmutableList ReturnImmutableListCopy()
  46.         {
  47.             var copy = new List<int>();
  48.  
  49.             foreach (var item in this.integers)
  50.             {
  51.                 copy.Add(item);
  52.             }
  53.  
  54.             return new ImmutableList(copy);
  55.         }
  56.     }
  57. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement