Advertisement
Guest User

Untitled

a guest
May 3rd, 2017
92
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.17 KB | None | 0 0
  1. using System.CodeDom.Compiler;
  2. using System.Reflection;
  3.  
  4. namespace ReflectionIssue
  5. {
  6.     class Program
  7.     {
  8.         static void Main(string[] args)
  9.         {
  10.             CompilerParameters cp = new CompilerParameters();
  11.             cp.GenerateInMemory = true;
  12.             cp.GenerateExecutable = false;
  13.  
  14.             string[] sources = new string[1];
  15.             sources[0] =
  16.                 @"
  17.                using System.Collections.Concurrent;
  18.                public static class TestClass
  19.                {
  20.                     public static void TestMethod()
  21.                     {
  22.                        //ConcurrentBag<int> a = new ConcurrentBag<int>(); // FAILS IF NOT COMMENTED OUT - WTF
  23.                        ConcurrentDictionary<int, int> b = new ConcurrentDictionary<int, int>();
  24.                         ConcurrentQueue<int> c = new ConcurrentQueue<int>();
  25.                         ConcurrentStack<int> d = new ConcurrentStack<int>();       
  26.                    }
  27.                }
  28.            ";
  29.  
  30.             CompilerResults r = CodeDomProvider.CreateProvider("CSharp").CompileAssemblyFromSource(cp, sources);
  31.             Assembly asm = r.CompiledAssembly;
  32.         }  
  33.     }
  34. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement