daver32 / InterfaceGenerator

A simple source generator that creates interfaces by implementations.
MIT License
36 stars 14 forks source link

Keyword parameter identifiers don't get escaped #5

Closed Atvaark closed 2 years ago

Atvaark commented 2 years ago

Hey,

while testing this source generator with another one I noticed an issue with some generated parameter names. Methods that use keywords such as long as identifiers don't get properly prefixed with @ in the generated interface.

Example:

public void VoidMethodWithKeywordParam(long @long)

results in:

void VoidMethodWithKeywordParam(long long); // CS1001 Identifier expected

but should be:

void VoidMethodWithKeywordParam(long @long);

This should be the line where param.Name needs to be checked and sometimes prefixed. https://github.com/daver32/InterfaceGenerator/blob/9382c69cf8c72bdc21bcb1e2984f4b7f3902dbae/InterfaceGenerator/AutoInterfaceGenerator.cs#L327

e. g. AutoRest is handling these identifiers like this: 1. Writing the identifier. 2. Checking for C# keywords

daver32 commented 2 years ago

Thanks for the heads up, I've just added this in v1.0.8