monkey0506 / native-generic-delegates

Generic C# delegates for P/Invoke.
Other
8 stars 0 forks source link

`GetMarshalAsFromOperation` does not append `null` literals #6

Closed monkey0506 closed 1 year ago

monkey0506 commented 1 year ago

Describe the issue

GetMarshalAsFromOperation checks the value argument for a constant value. Because the runtime type of the represented value in this method is always MarshalAsAttribute or MarshalAsAttribute[], the only possible constant value is null. The marshalAsStrings argument should have a null element added if the value argument has a constant value (null).

Proposed solution

When value has a constant value (null), a null element should be added to marshalAsStrings:

if (value.ConstantValue.HasValue) // value is null
{
    marshalAsStrings.Add(null); // <--- add this line
    return;
}

Additional considerations

Work on #1 is already underway and the definition of GetMarshalAsFromOperation has moved to a different file. Because git does not track this refactoring, implementing this change will wait until work on #1 is completed and merged into the incremental-generator branch.

monkey0506 commented 1 year ago

Fixed by #8.