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

Add ConditionalAttribute to codegen attributes #3321

Open
heaths opened this issue Apr 26, 2023 · 0 comments
Open

Add ConditionalAttribute to codegen attributes #3321

heaths opened this issue Apr 26, 2023 · 0 comments

Comments

@heaths
Copy link
Member

heaths commented Apr 26, 2023

The various codegen attributes don't need to ship in productio assemblies. They cause little harm, but still get enumerated and, as with #3261, can even cause (admitted small) perf hits.

We should put ConditionalAttributes on these attributes. .NET does that for SuppressMessageAttribute, for example. Only when CODE_ANALYSIS is passed - during code analysis - is the attribute even included. It's elided for normally compiled code. We could do the same with a CODEGEN symbol or something that autorest.csharp itself could pass, such that any scripts/MSBuild target - however it's called - uses it.

This would make the code a little leaner.

See Azure/azure-sdk-for-net#35376 (comment) for context.

@heaths heaths changed the title This should fix https://github.com/Azure/autorest.csharp/issues/3261 as well, since https://github.com/dotnet/roslyn-analyzers/pull/6114 fixed this in the newer NetAnalyzers. While my attempt to fix this in https://github.com/Azure/autorest.csharp/pull/3262 is still a valid solution, it has a non-obvious bug tail that is probably not worth the time. Add ConditionalAttribute to codegen attributes Apr 26, 2023
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

1 participant