Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support for nullable/optional value types #63

Open
Tracked by #1
lemonmojo opened this issue Nov 9, 2023 · 6 comments
Open
Tracked by #1

Support for nullable/optional value types #63

lemonmojo opened this issue Nov 9, 2023 · 6 comments
Labels
bug Something isn't working generator help wanted Extra attention is needed

Comments

@lemonmojo
Copy link
Member

ie. bool TryGetId(out Guid? id)

I think that's currently an unsupported scenario.
Have to check.

@lemonmojo lemonmojo added bug Something isn't working generator help wanted Extra attention is needed labels Nov 9, 2023
@lemonmojo
Copy link
Member Author

So the reason is that under the cover it's actually a generic Nullable<T>: https://learn.microsoft.com/en-us/dotnet/api/system.nullable-1?view=net-7.0

@lemonmojo
Copy link
Member Author

Example of what such a parameter looks like:
Screenshot 2023-11-10 at 11 31 42

@lemonmojo lemonmojo changed the title Support for optional value type out parameters Support for nullable/optional value types Nov 12, 2023
@lemonmojo lemonmojo mentioned this issue Jul 12, 2023
57 tasks
@lemonmojo
Copy link
Member Author

lemonmojo commented Nov 12, 2023

Same applies to primitives btw. ie. int?/Nullable<int>.

@lemonmojo
Copy link
Member Author

lemonmojo commented Nov 12, 2023

Partial Strategy: Add an extension method to System.Type: bool IsNullableValueType(this Type type, out Type? valueType) so that we can figure out if the targeted type is a nullable value type and if it is, get the underlying type as an out parameter.

As a first step, this information can be used to emit a more detailed unsupported type reason message.

See https://learn.microsoft.com/en-us/dotnet/api/system.nullable.getunderlyingtype?view=net-7.0

@lemonmojo
Copy link
Member Author

I think that once a TypeDescriptor is created for such a type, we can add conversions there which will then be used by later generation phases.

@lemonmojo
Copy link
Member Author

lemonmojo commented Nov 13, 2023

fc54eec added support for nullable structs (no support yet for nullable primitives and enums).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working generator help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

1 participant