royalapplications / beyondnet

A toolset that makes it possible to call .NET code from other programming languages, including C, Swift and Kotlin.
https://royalapps.com
MIT License
111 stars 5 forks source link

Support for nullable/optional value types #63

Open lemonmojo opened 12 months ago

lemonmojo commented 12 months ago

ie. bool TryGetId(out Guid? id)

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

lemonmojo commented 12 months ago

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 commented 12 months ago

Example of what such a parameter looks like:

Screenshot 2023-11-10 at 11 31 42
lemonmojo commented 12 months ago

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

lemonmojo commented 12 months ago

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 commented 12 months ago

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 commented 11 months ago

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