-
Notifications
You must be signed in to change notification settings - Fork 188
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: Splitting some C# related extensions in a separate file (#2697)
Splitting some C# related extensions in a separate file Co-authored-by: Rouke Broersma <[email protected]>
- Loading branch information
1 parent
b4f22e5
commit bb1f129
Showing
2 changed files
with
46 additions
and
38 deletions.
There are no files selected for viewing
41 changes: 41 additions & 0 deletions
41
src/Stryker.Core/Stryker.Core/Initialisation/Buildalyzer/IAnalyzerResultCSharpExtensions.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
using System; | ||
using Buildalyzer; | ||
using Microsoft.CodeAnalysis; | ||
using Microsoft.CodeAnalysis.CSharp; | ||
using Stryker.Core.Options; | ||
|
||
namespace Stryker.Core.Initialisation.Buildalyzer | ||
{ | ||
public static class IAnalyzerResultCSharpExtensions | ||
{ | ||
public static CSharpCompilationOptions GetCompilationOptions(this IAnalyzerResult analyzerResult) | ||
{ | ||
var compilationOptions = new CSharpCompilationOptions(analyzerResult.GetOutputKind()) | ||
.WithNullableContextOptions(analyzerResult.GetNullableContextOptions()) | ||
.WithAllowUnsafe(analyzerResult.GetPropertyOrDefault("AllowUnsafeBlocks", true)) | ||
.WithAssemblyIdentityComparer(DesktopAssemblyIdentityComparer.Default) | ||
.WithConcurrentBuild(true) | ||
.WithModuleName(analyzerResult.GetAssemblyName()) | ||
.WithOverflowChecks(analyzerResult.GetPropertyOrDefault("CheckForOverflowUnderflow", false)); | ||
|
||
if (analyzerResult.IsSignedAssembly() && analyzerResult.GetAssemblyOriginatorKeyFile() is var keyFile && keyFile is not null) | ||
{ | ||
compilationOptions = compilationOptions.WithCryptoKeyFile(keyFile) | ||
.WithStrongNameProvider(new DesktopStrongNameProvider()); | ||
} | ||
return compilationOptions; | ||
} | ||
|
||
public static CSharpParseOptions GetParseOptions(this IAnalyzerResult analyzerResult, StrykerOptions options) => new CSharpParseOptions(options.LanguageVersion, DocumentationMode.None, preprocessorSymbols: analyzerResult.PreprocessorSymbols); | ||
|
||
private static NullableContextOptions GetNullableContextOptions(this IAnalyzerResult analyzerResult) | ||
{ | ||
if (!Enum.TryParse(analyzerResult.GetPropertyOrDefault("Nullable", "enable"), true, out NullableContextOptions nullableOptions)) | ||
{ | ||
nullableOptions = NullableContextOptions.Enable; | ||
} | ||
|
||
return nullableOptions; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters