Enforce Code Cleanup code-style that is not available in editorconfig

72 Views Asked by At

I am coding a transpiler that is translating an old language to C#.

In the old language it was possible to assign a variable to another variable of another type.
This could for example be assigning an int32 variable to an int16 variable.
In C# ofcourse, you would need to cast it like:

shortVariable = (short)intVariable;

The annoying thing is that when i am translating, i dont always know if it is actually necessary to cast, but i need to do it for when it is.
The result is that i have a "million"(many) redundant type casts after transpiling all the code.

Luckily for me i can get the code cleanup tool in visual studio to clean them up for me.
However, that is not the way i would like to go and i know that many of the cleanup tool's settings can be put in a .editorconfig file and be enforced on build.
I like that.

Unluckily for me the IDE0004 does not have any "code-style options", so as i understand, i am not able to put it in the .editorconfig file.

I have the transpiled code as a string and i am able to use Roslyn to get the compilation afterwards.
Does anyone know of a way how i can enforce the IDE0004 code style on a build or with Roslyn or something?

I refuse to believe that there is nothing i can do other than to create some Roslyn code to do it myself.

0

There are 0 best solutions below