This option is the inverse of the previous option. Instead of using a variable to replace a lengthy expression, it now replaces all of the variables with the original expression. Consider the following code segment:
Dim lSizeWidth As Integer = Me.Size.Width If lSizeWidth > 200 Then ... End If If lSizeWidth > 100 Then ... End If
If you right-click on
lSizeWidth and select Refactor -> Inline Temp (see
Figure 15), it will now replace all occurrences of the
lSizeWidth variable with
Figure 15. Replacing a variable with its original expression
Your code will now become:
If Me.Size.Width > 200 Then ... End If If Me.Size.Width > 100 Then ... End If
There's one caveat, though. If you have a statement that performs some changes
lSizeWidth variable (see the code below), then Refactor will not be
able to perform the Inline Temp refactoring for you:
Dim lSizeWidth As Integer = Me.Size.Width If lSizeWidth > 200 Then ... End If lSizeWidth -= 100 If lSizeWidth > 100 Then ... End If
Consider the following block of code, which consumes a web service:
Dim result() As StockWS.Quote = _ My.WebServices.StockQuotes.GetStockQuotes("MSFT") MsgBox(result(0).StockQuote)
You may reference the web service in a number of places in your application. In such cases, it may be better to extract the above logic and expose it as a property so that other parts of your code can simply access the property and you will not need to write code to consume the web service again. To do so, highlight the web service code (see Figure 16), right-click, and select Refactor -> Extract Property.
Figure 16. Extracting a block of code as a property
The web service code would now be exposed as a property and the original code would be replaced with a property call:
Private ReadOnly Property MyProperty() As StockWS.Quote() Get Return My.WebServices.StockQuotes.GetStockQuotes("MSFT") End Get End Property ... ... Dim result() As StockWS.Quote = MyProperty MsgBox(result(0).StockQuote)
You can create overloaded methods easily in your class by right-clicking on a method name and then selecting Refactor -> Create Overload (see Figure 17).
Figure 17. Creating an overloaded method
An overloaded method is created and you can use the various keyboard options (see Figure 18) to include/exclude parameters.
Figure 18. Modifying the overloaded method