Is there a way to create a custom quick fix suggestion?

For example, I would like all PUBLIC const/static read-only fields to be placed in a "Constants.cs" file. Is there a way to do that?

0
1 comment

Yes, you can write a plugin that can look for public const or static fields, highlight them with a warning or suggestion, and then attach a Quick Fix to this warning. The quick fix would need to rewrite your code to remove the field and add it back into Constants.cs, and then fix up any existing references. This is a lot of work, so it might be better to invoke the Move refactoring to do that for you.

You can find more information on creating a plugin in the developer guide, with details on how to add a highlight and how to create a Quick Fix. The docs for Quick Fixes are a little out of date, although mostly still correct. You can see an example in the Unity plugin. The Unity plugin also has an example of how to invoke a refactoring programmatically, although it's invoking the Change Signature fix. The principle is the same.

0

Please sign in to leave a comment.