beyondnet icon indicating copy to clipboard operation
beyondnet copied to clipboard

Support for nullable/optional value types

Open lemonmojo opened this issue 2 years ago • 6 comments

ie. bool TryGetId(out Guid? id)

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

lemonmojo avatar Nov 09 '23 20:11 lemonmojo

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 avatar Nov 10 '23 10:11 lemonmojo

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

lemonmojo avatar Nov 10 '23 10:11 lemonmojo

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

lemonmojo avatar Nov 12 '23 08:11 lemonmojo

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 avatar Nov 12 '23 10:11 lemonmojo

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 avatar Nov 12 '23 13:11 lemonmojo

https://github.com/royalapplications/beyondnet/commit/fc54eecb55c8052e82d5f41b5a372d2530fc04b7 added support for nullable structs (no support yet for nullable primitives and enums).

lemonmojo avatar Nov 13 '23 10:11 lemonmojo