There are times when you realize that a local variable or a field reference within a method would be more useful if it was a parameter. Having a new parameter on a method will increase its flexibility for consumers. To convert the local variable, you should remove its declaration from the body of the method, add it as a parameter and replace all occurrences of a local to a new parameter. The same steps must be performed in the case of field references. Furthermore, all method references in the entire solution should be updated to pass a new value as an argument to a method with a new signature.
Read more…
There are a couple of visibility-changing refactorings shipped in DevExpress Refactor! Pro.
This refactoring allows you to quickly reduce the visibility of a member to match the highest calling visibility, in other words, to restrict the visibility as much as possible.
The scope of a variable declaration determines its visibility to the rest of a program. Scopes can be member-level, class-level and nested, where an inner scope may re-declare the meaning of a variable from an outer scope.
When declared inside a member, the scope of the variable is the entire member after the variable declaration, including all nested code blocks. This means that the variable is available to use within the member but when control passes to another member, the variable is unavailable.
Read more…
Unlike the local variable declarations, fields are simply variables that are declared directly within the code block of a class or a structure. Fields are declared in the type block by specifying the access level of the field, the type of the field and the name of the field. A field may also include a readonly modifier. This type of field can only have its value set directly in its declaration or from within a constructor of its containing class.
Read more…