forked from dotnet/runtime
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implement support for configurable generator options. (dotnet/runtime…
…lab#458) Commit migrated from dotnet/runtimelab@9649d43
- Loading branch information
1 parent
d24260a
commit 9bc3120
Showing
13 changed files
with
274 additions
and
49 deletions.
There are no files selected for viewing
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
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
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
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
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
19 changes: 19 additions & 0 deletions
19
...Runtime.InteropServices/gen/DllImportGenerator/Microsoft.Interop.DllImportGenerator.props
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,19 @@ | ||
<Project> | ||
<!-- | ||
Define all of the configuration options supported for the DllImportGenerator. | ||
To use, set an MSBuild property with the name of the option to `true`. | ||
See OptionsHelper.cs for more information on usage. | ||
--> | ||
<ItemGroup> | ||
<!-- | ||
Use the System.Runtime.InteropServices.Marshal type instead of | ||
the System.Runtime.InteropServices.MarshalEx type when emitting code. | ||
--> | ||
<CompilerVisibleProperty Include="DllImportGenerator_UseMarshalType" /> | ||
<!-- | ||
Generate a stub that forwards to a runtime implemented P/Invoke stub instead | ||
of generating a stub that handles all of the marshalling. | ||
--> | ||
<CompilerVisibleProperty Include="DllImportGenerator_GenerateForwarders" /> | ||
</ItemGroup> | ||
</Project> |
26 changes: 26 additions & 0 deletions
26
src/libraries/System.Runtime.InteropServices/gen/DllImportGenerator/OptionsHelper.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,26 @@ | ||
using Microsoft.CodeAnalysis; | ||
using Microsoft.CodeAnalysis.Diagnostics; | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Diagnostics; | ||
using System.Runtime.InteropServices; | ||
|
||
namespace Microsoft.Interop | ||
{ | ||
public static class OptionsHelper | ||
{ | ||
public const string UseMarshalTypeOption = "build_property.DllImportGenerator_UseMarshalType"; | ||
public const string GenerateForwardersOption = "build_property.DllImportGenerator_GenerateForwarders"; | ||
|
||
private static bool GetBoolOption(this AnalyzerConfigOptions options, string key) | ||
{ | ||
return options.TryGetValue(key, out string? value) | ||
&& bool.TryParse(value, out bool result) | ||
&& result; | ||
} | ||
|
||
internal static bool UseMarshalType(this AnalyzerConfigOptions options) => options.GetBoolOption(UseMarshalTypeOption); | ||
|
||
internal static bool GenerateForwarders(this AnalyzerConfigOptions options) => options.GetBoolOption(GenerateForwardersOption); | ||
} | ||
} |
Oops, something went wrong.