sharpenrocks / Sharpen

Visual Studio extension that intelligently introduces new C# features into your existing codebase
https://sharpen.rocks
MIT License
418 stars 32 forks source link

Add option to ignore CompilerGenerated code #35

Closed Thieum closed 4 years ago

Thieum commented 4 years ago

It would be nice to be able to ignore classes and/or methods marked with the CompilerGenerated attribute, since this code cannot be improved, without it being regenerated with the previous syntax.

ironcev commented 4 years ago

Hi @Thieum, thanks for the proposal! Sharpen already ignores generated code, but on the file level. It supports a very simple heuristics with a comment already in code that we want to have it configurable and more powerful (see GeneratedCodeDetection.cs).

I wasn't thinking about the CompilerGenerated attribute though, because I've actually never seen it in code. It is usually added to the metadata of the elements in assemblies generated by the compiler like e.g. the classes that implement lambdas and closures.

Do you maybe have a concrete example of a code that uses the CompilerGenerated attribute?

Thieum commented 4 years ago

@ironcev I thought I did, but those were manually added to the result of a protocol buffer file generated by the protocol buffer compiler, after investigation. I will open a ticket in protobuf, to check if that's something of interest to add to the compiler on their side. That kinda lowers the interest of this ticket for both of us at the moment, since I don't have a concrete example that would require this feature :(

Thieum commented 4 years ago

Also the proper attribute to use might be GeneratedCodeAttribute since CompilerGenerated is used by the c# compiler itself as you pointed out, not by third party tools.

Thieum commented 4 years ago

I'll close this issue for now and revisit if a proper use case arises.

ironcev commented 4 years ago

Hi @Thieum, I just wanted to say thanks for pointing out the GeneratedCodeAttribute. My original idea was to have the configuration settings similar to those in ReSharper:

image

Once the feature gains more on relevance I will for sure add support for the GeneratedCodeAttribute as well. Thanks!