monkey0506 / native-generic-delegates

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

`INativeAction` and `IUnmanagedAction` interfaces do not generate source for factory methods #40

Closed monkey0506 closed 1 month ago

monkey0506 commented 1 month ago

Describe the issue

The INativeAction and IUnmanagedAction interfaces without type arguments are failing to generate source for their respective factory methods.

Proposed solution

The root cause is indeterminate at this time. These interfaces should generate source that mirrors what is generated for the interfaces that have type arguments.

This may be a shortcoming at practically any point in the generator pipeline, and will require further investigation.

Additional considerations

None.

monkey0506 commented 1 month ago

The reason this is failing is because GenericSymbolReferenceTree doesn't return any symbols that aren't generic, and INativeAction and IUnmanagedAction are not generic.

Instead, we should add a separate SyntaxValueProvider to discover references to these two interfaces' factory methods and create the MethodReferences for them as an additional step.

We can minimize the number of additional symbols we need to find by checking (in the syntax provider predicate) for a MemberAccessExpressionSyntax whose Expression is an IdentifierNameSyntax whose Identifier matches the name of the interface. The Name of the MemberAccessExpressionSyntax should be "FromAction" or "FromFunctionPointer". The MemberAccessExpressionSyntax should also have a grandparent node that is an InvocationExpressionSyntax. After filtering the nodes by this criteria, the first transform can use the IOperation API to perform a final validation of the INamedTypeSymbol containing the invoked method.

monkey0506 commented 1 month ago

Fixed by #41.