示例#1
0
        /// <summary>
        /// Create in-memory compilation of library
        /// </summary>
        private void CreateLibrary()
        {
            if (string.IsNullOrEmpty(_settings.LibraryRootDirectory) ||
                !Directory.Exists(_settings.LibraryRootDirectory))
            {
                return;
            }
            try
            {
                lock ( Sync )
                {
                    var builder = new CompilationBuilder();

                    // adding all *.cs files
                    foreach (var path in Directory.GetFiles(_settings.LibraryRootDirectory, "*.cs", SearchOption.AllDirectories))
                    {
                        builder.AddSourceFile(path);
                    }
                    _compilation = builder.Build();

                    var errors = builder.ValidateCompilation(_compilation);
                    if (errors != null && errors.Any())
                    {
                        MessageBox.Show("There were compilation errors of library: " + Environment.NewLine
                                        + string.Join(Environment.NewLine, errors));
                    }

                    _codeImporter = new CodeImporter(_compilation,
                                                     location => File.ReadAllText(location.FileName).Substring(location.Span.Start, location.Span.Length));
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("Error during library compilation: " + ex.Message);
            }
        }