Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Custom "method signature" code can be replaced with call to IMethodSymbol.ToDisplayString(...) #66

Closed
simonmckenzie opened this issue Dec 6, 2024 · 2 comments

Comments

@simonmckenzie
Copy link
Contributor

I have noticed that while the project has a lot of logic for the generation of method parameters, return types, generic type constraints, etc., the same result can be obtained by using .ToDisplayString(FullyQualifiedDisplayFormat) on the IMethodSymbol.

This means we could delete almost all of this logic and replace it with one line:

https://github.com/codecentric/net_automatic_interface/blob/9d66cad06170853f5b1741573e474f7b6592ee8b/AutomaticInterface/AutomaticInterface/Builder.cs#L100C25-L126C6

... and no doubt similar simplifications could be done for other parts of the interface generation.

What I'm not certain about is whether this is a good idea or not. I've done this replacement locally and all tests pass, but it does mean that it makes later customisation difficult, since all rendering decisions are passed off to Roslyn. Trying to address issues like #62, where the feature request is for something outside what Roslyn offers, would become much harder. Not sure!

@simonmckenzie
Copy link
Contributor Author

Closing. It turns out I had misunderstood the purpose of ToDisplayString - while using it with a fully qualified format does generate valid code for type symbols, things that aren't type symbols (like default parameter values) aren't guaranteed to be compilable.

dotnet/roslyn#56573

@ChristianSauer
Copy link
Collaborator

Yes, there are several instances where I would like to let something else do the string mungling but it doesn't quite fit. A pity.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants