NArrange.Tests.CSharp.CSharpTestFile.GetAssembly C# (CSharp) Method

GetAssembly() private static method

Gets the assembly.
private static GetAssembly ( string resourceName, bool targetCSharp6 = false ) : Assembly
resourceName string Name of the resource.
targetCSharp6 bool
return System.Reflection.Assembly
        private static Assembly GetAssembly(string resourceName, bool targetCSharp6 = false)
        {
            Assembly assembly = null;
            if (!_compiledSourceFiles.TryGetValue(resourceName, out assembly))
            {
                using (TextReader reader = GetTestFileReader(resourceName))
                {
                    string source = reader.ReadToEnd();

                    CompilerResults results = Compile(source, targetCSharp6);

                    if (results.Errors.Count > 0)
                    {
                        CompilerError error = null;

                        error = TestUtilities.GetCompilerError(results);

                        if (error != null)
                        {
                            string messageFormat =
                                "Test source code should not produce compiler errors. " +
                                "Error: {0} - {1}, line {2}, column {3} ";
                            Assert.Fail(
                                messageFormat,
                                error.ErrorText,
                                resourceName,
                                error.Line,
                                error.Column);
                        }

                        assembly = results.CompiledAssembly;
                    }
                }

                if (assembly != null)
                {
                    _compiledSourceFiles.Add(resourceName, assembly);
                }
            }

            return assembly;
        }