本文整理汇总了C#中Microsoft.CodeAnalysis.AdhocWorkspace.AddAdditionalDocument方法的典型用法代码示例。如果您正苦于以下问题:C# AdhocWorkspace.AddAdditionalDocument方法的具体用法?C# AdhocWorkspace.AddAdditionalDocument怎么用?C# AdhocWorkspace.AddAdditionalDocument使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Microsoft.CodeAnalysis.AdhocWorkspace
的用法示例。
在下文中一共展示了AdhocWorkspace.AddAdditionalDocument方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: CreateSolution
/// <summary>
/// Creates a solution that will be used as parent for the sources that need to be checked.
/// </summary>
/// <param name="projectId">The project identifier to use.</param>
/// <param name="language">The language for which the solution is being created.</param>
/// <returns>The created solution.</returns>
protected virtual Solution CreateSolution(ProjectId projectId, string language)
{
var compilationOptions = new CSharpCompilationOptions(OutputKind.DynamicallyLinkedLibrary, allowUnsafe: true);
var additionalDiagnosticOptions = this.GetDisabledDiagnostics().Select(id => new KeyValuePair<string, ReportDiagnostic>(id, ReportDiagnostic.Suppress));
var newSpecificOptions = compilationOptions.SpecificDiagnosticOptions.AddRange(additionalDiagnosticOptions);
compilationOptions = compilationOptions.WithSpecificDiagnosticOptions(newSpecificOptions);
Solution solution = new AdhocWorkspace()
.CurrentSolution
.AddProject(projectId, TestProjectName, TestProjectName, language)
.WithProjectCompilationOptions(projectId, compilationOptions)
.AddMetadataReference(projectId, MetadataReferences.CorlibReference)
.AddMetadataReference(projectId, MetadataReferences.SystemReference)
.AddMetadataReference(projectId, MetadataReferences.SystemCoreReference)
.AddMetadataReference(projectId, MetadataReferences.CSharpSymbolsReference)
.AddMetadataReference(projectId, MetadataReferences.CodeAnalysisReference);
var settings = this.GetSettings();
if (!string.IsNullOrEmpty(settings))
{
var documentId = DocumentId.CreateNewId(projectId);
solution = solution.AddAdditionalDocument(documentId, SettingsFileName, settings);
}
ParseOptions parseOptions = solution.GetProject(projectId).ParseOptions;
return solution.WithProjectParseOptions(projectId, parseOptions.WithDocumentationMode(DocumentationMode.Diagnose));
}
示例2: CreateSolution
/// <summary>
/// Creates a solution that will be used as parent for the sources that need to be checked.
/// </summary>
/// <param name="projectId">The project identifier to use.</param>
/// <param name="language">The language for which the solution is being created.</param>
/// <returns>The created solution.</returns>
protected virtual Solution CreateSolution(ProjectId projectId, string language)
{
var compilationOptions = new CSharpCompilationOptions(OutputKind.DynamicallyLinkedLibrary, allowUnsafe: true);
Solution solution = new AdhocWorkspace()
.CurrentSolution
.AddProject(projectId, TestProjectName, TestProjectName, language)
.WithProjectCompilationOptions(projectId, compilationOptions)
.AddMetadataReference(projectId, MetadataReferences.CorlibReference)
.AddMetadataReference(projectId, MetadataReferences.SystemReference)
.AddMetadataReference(projectId, MetadataReferences.SystemCoreReference)
.AddMetadataReference(projectId, MetadataReferences.CSharpSymbolsReference)
.AddMetadataReference(projectId, MetadataReferences.CodeAnalysisReference);
var publicApi = this.GetUnshippedPublicApi();
if (publicApi != null)
{
var documentId = DocumentId.CreateNewId(projectId);
solution = solution.AddAdditionalDocument(documentId, DeclarePublicAPIAnalyzer.UnshippedFileName, publicApi);
}
publicApi = this.GetShippedPublicApi();
if (publicApi != null)
{
var documentId = DocumentId.CreateNewId(projectId);
solution = solution.AddAdditionalDocument(documentId, DeclarePublicAPIAnalyzer.ShippedFileName, publicApi);
}
ParseOptions parseOptions = solution.GetProject(projectId).ParseOptions;
return solution.WithProjectParseOptions(projectId, parseOptions.WithDocumentationMode(DocumentationMode.Diagnose));
}
示例3: CreateSolution
/// <summary>
/// Creates a solution that will be used as parent for the sources that need to be checked.
/// </summary>
/// <param name="projectId">The project identifier to use.</param>
/// <param name="language">The language for which the solution is being created.</param>
/// <returns>The created solution.</returns>
protected virtual Solution CreateSolution(ProjectId projectId, string language)
{
var compilationOptions = new CSharpCompilationOptions(OutputKind.DynamicallyLinkedLibrary, allowUnsafe: true);
Solution solution = new AdhocWorkspace()
.CurrentSolution
.AddProject(projectId, TestProjectName, TestProjectName, language)
.WithProjectCompilationOptions(projectId, compilationOptions)
.AddMetadataReference(projectId, MetadataReferences.CorlibReference)
.AddMetadataReference(projectId, MetadataReferences.SystemReference)
.AddMetadataReference(projectId, MetadataReferences.SystemCoreReference)
.AddMetadataReference(projectId, MetadataReferences.CSharpSymbolsReference)
.AddMetadataReference(projectId, MetadataReferences.CodeAnalysisReference);
solution.Workspace.Options =
solution.Workspace.Options
.WithChangedOption(FormattingOptions.IndentationSize, language, this.IndentationSize)
.WithChangedOption(FormattingOptions.TabSize, language, this.TabSize)
.WithChangedOption(FormattingOptions.UseTabs, language, this.UseTabs);
var settings = this.GetSettings();
StyleCopSettings defaultSettings = new StyleCopSettings();
if (this.IndentationSize != defaultSettings.Indentation.IndentationSize
|| this.UseTabs != defaultSettings.Indentation.UseTabs
|| this.TabSize != defaultSettings.Indentation.TabSize)
{
var indentationSettings = [email protected]"
{{
""settings"": {{
""indentation"": {{
""indentationSize"": {this.IndentationSize},
""useTabs"": {this.UseTabs.ToString().ToLowerInvariant()},
""tabSize"": {this.TabSize}
}}
}}
}}
";
if (string.IsNullOrEmpty(settings))
{
settings = indentationSettings;
}
else
{
JObject mergedSettings = JsonConvert.DeserializeObject<JObject>(settings);
mergedSettings.Merge(JsonConvert.DeserializeObject<JObject>(indentationSettings));
settings = JsonConvert.SerializeObject(mergedSettings);
}
}
if (!string.IsNullOrEmpty(settings))
{
var documentId = DocumentId.CreateNewId(projectId);
solution = solution.AddAdditionalDocument(documentId, SettingsHelper.SettingsFileName, settings);
}
ParseOptions parseOptions = solution.GetProject(projectId).ParseOptions;
return solution.WithProjectParseOptions(projectId, parseOptions.WithDocumentationMode(DocumentationMode.Diagnose));
}
示例4: CreateSolution
/// <summary>
/// Creates a solution that will be used as parent for the sources that need to be checked.
/// </summary>
/// <param name="projectId">The project identifier to use.</param>
/// <param name="language">The language for which the solution is being created.</param>
/// <returns>The created solution.</returns>
protected virtual Solution CreateSolution(ProjectId projectId, string language)
{
var compilationOptions = new CSharpCompilationOptions(OutputKind.DynamicallyLinkedLibrary, allowUnsafe: true);
Solution solution = new AdhocWorkspace()
.CurrentSolution
.AddProject(projectId, TestProjectName, TestProjectName, language)
.WithProjectCompilationOptions(projectId, compilationOptions)
.AddMetadataReference(projectId, MetadataReferences.CorlibReference)
.AddMetadataReference(projectId, MetadataReferences.SystemReference)
.AddMetadataReference(projectId, MetadataReferences.SystemCoreReference)
.AddMetadataReference(projectId, MetadataReferences.CSharpSymbolsReference)
.AddMetadataReference(projectId, MetadataReferences.CodeAnalysisReference);
var settings = this.GetSettings();
if (!string.IsNullOrEmpty(settings))
{
var documentId = DocumentId.CreateNewId(projectId);
solution = solution.AddAdditionalDocument(documentId, SettingsHelper.PublicApiFileName, settings);
}
ParseOptions parseOptions = solution.GetProject(projectId).ParseOptions;
return solution.WithProjectParseOptions(projectId, parseOptions.WithDocumentationMode(DocumentationMode.Diagnose));
}