roslynator
roslynator copied to clipboard
Introduce field (again)
First, this is not a duplicate of #141, #141 actually I don't use it nor found it useful sorry for this.
Now what I really want is to have the opportunity to introduce fields (and may be also properties) on the current class when I have the cursor over a local variable, or when I'm selecting a complete expression.
What we have now is: "Introduce local for '....'" when you select an expression like "new DateTime()" I'd like to have available "Introduce field for ... " like this https://www.jetbrains.com/help/resharper/Refactorings__Introduce_Field.html
Roslynator already supports "Introduce constan for" which will introduce a class level constant member.
When introducing a field from a local expression (or local variable selected also) it might not make sense on how to initialize this field, specially if the data is not available in global scope, e.g. the field is initialized with the addition of two local variables. But that's ok, the filed can just be null or zero or not initialized until the code runs there, that will be "Current Member" I don't know if roslynator can do this.
The main goal is to have a refactoring which will create a field of the correct type at the class level. Most likely this field will be reused on another method, or used as a cache of something and checked later if it needs to be reinitialized, etc.
"Introduce field" is probably the number one resharper refactoring that I use! I'd love to see it here.