-
Notifications
You must be signed in to change notification settings - Fork 184
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
C#: use nullable types for non-nested options (#977)
We now generate bindings which use nullable types (e.g. `uint?`) to represent non-nested `option` types. Nested `option`s, such as `option<option<T>>` still use the `Option` class except for the innermost `option` in order to avoid ambiguity. Fixes #964 Signed-off-by: Joel Dice <joel.dice@fermyon.com>
- Loading branch information
Showing
6 changed files
with
135 additions
and
25 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
using System.Diagnostics; | ||
using OptionsWorld.wit.imports.test.options; | ||
|
||
namespace OptionsWorld.wit.exports.test.options | ||
{ | ||
public class TestImpl : ITest | ||
{ | ||
public static void OptionNoneParam(string? a) | ||
{ | ||
Debug.Assert(a == null); | ||
} | ||
|
||
public static string? OptionNoneResult() | ||
{ | ||
return null; | ||
} | ||
|
||
public static void OptionSomeParam(string? a) | ||
{ | ||
Debug.Assert(a == "foo"); | ||
} | ||
|
||
public static string? OptionSomeResult() | ||
{ | ||
return "foo"; | ||
} | ||
|
||
public static string? OptionRoundtrip(string? a) | ||
{ | ||
return a; | ||
} | ||
|
||
public static Option<uint?> DoubleOptionRoundtrip(Option<uint?> a) | ||
{ | ||
return a; | ||
} | ||
} | ||
} | ||
|
||
namespace OptionsWorld | ||
{ | ||
public class OptionsWorldImpl : IOptionsWorld | ||
{ | ||
public static void TestImports() | ||
{ | ||
TestInterop.OptionNoneParam(null); | ||
TestInterop.OptionSomeParam("foo"); | ||
Debug.Assert(TestInterop.OptionNoneResult() == null); | ||
Debug.Assert(TestInterop.OptionSomeResult() == "foo"); | ||
Debug.Assert(TestInterop.OptionRoundtrip("foo") == "foo"); | ||
Debug.Assert(TestInterop.DoubleOptionRoundtrip(new Option<uint?>(42)).Value == 42); | ||
Debug.Assert(TestInterop.DoubleOptionRoundtrip(new Option<uint?>(null)).Value == null); | ||
Debug.Assert(!TestInterop.DoubleOptionRoundtrip(Option<uint?>.None).HasValue); | ||
} | ||
} | ||
} |
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