/// <summary>
        /// Compiles the specified data source wrapper sources into a Roslyn compilation object.
        /// </summary>
        private static Compilation CompileDataSourceWrapperSources(RoslynExpressionCompilerState state, String output, IEnumerable <DataSourceWrapperInfo> infos, IEnumerable <String> references, Boolean debug)
        {
            var trees = new ConcurrentBag <SyntaxTree>()
            {
                CSharpSyntaxTree.ParseText(WriteCompilerMetadataFile(debug), CSharpParseOptions.Default, "CompilerMetadata.cs")
            };
            var mrefs = references.Distinct().Select(x => MetadataReference.CreateFromFile(Path.IsPathRooted(x) ? x : Assembly.Load(x).Location));

            Parallel.ForEach(infos, info =>
            {
                var path = state.GetWorkingFileForDataSourceWrapper(info);
                File.WriteAllText(path, info.DataSourceWrapperSourceCode);

                trees.Add(CSharpSyntaxTree.ParseText(info.DataSourceWrapperSourceCode, path: path));
            });

            var optimization = debug ? OptimizationLevel.Debug : OptimizationLevel.Release;
            var options      = new CSharpCompilationOptions(OutputKind.DynamicallyLinkedLibrary, optimizationLevel: optimization, deterministic: true);
            var compilation  = CSharpCompilation.Create("Ultraviolet.Presentation.CompiledExpressions.dll", trees, mrefs, options);

            return(compilation);
        }
        /// <summary>
        /// Converts an array of <see cref="Diagnostic"/> instances to a collection of <see cref="BindingExpressionCompilationError"/> objects.
        /// </summary>
        private static List <BindingExpressionCompilationError> CreateBindingExpressionCompilationErrors(RoslynExpressionCompilerState state,
                                                                                                         IEnumerable <DataSourceWrapperInfo> models, ImmutableArray <Diagnostic> diagnostics)
        {
            var result = new List <BindingExpressionCompilationError>();

            var workingDirectory = state.GetWorkingDirectory();

            var errorsByFile = diagnostics.Where(x => x.Severity == DiagnosticSeverity.Error && x.Location.IsInSource)
                               .GroupBy(x => Path.GetFileName(x.Location.SourceTree.FilePath)).ToDictionary(x => x.Key, x => x.ToList());

            foreach (var model in models)
            {
                var dataSourceWrapperFilename = Path.GetFileName(state.GetWorkingFileForDataSourceWrapper(model));
                var dataSourceErrors          = default(List <Diagnostic>);
                if (errorsByFile.TryGetValue(dataSourceWrapperFilename, out dataSourceErrors))
                {
                    foreach (var dataSourceError in dataSourceErrors)
                    {
                        var fullPathToFile = model.DataSourceWrapperName;
                        if (state.WriteErrorsToFile)
                        {
                            fullPathToFile = Path.GetFullPath(Path.Combine(workingDirectory,
                                                                           Path.ChangeExtension(model.DataSourceWrapperName, "cs")));
                        }

                        var line    = GetDiagnosticLine(dataSourceError);
                        var column  = GetDiagnosticColumn(dataSourceError);
                        var errno   = dataSourceError.Id;
                        var message = dataSourceError.GetMessage(CultureInfo.InvariantCulture);

                        result.Add(new BindingExpressionCompilationError(fullPathToFile, line, column, errno, message));
                    }
                }
            }

            return(result);
        }