Whole Tomato Software - Home
  • RSS Feed

Create from Usage

The Create from Usage collection of refactorings, for top-down programming, allows you to introduce code when and where you want—without changing your caret position or flipping between files. You can create classes or introduce enums, variables, and functions/methods at local, class, or global scope. Invoke this feature by typing a new symbol name and instructing Visual Assist to create the desired target. The correct target type is inferred.

Create New Class

Create new stub classes as you write code. Access Create from Usage from the VAssistX menu (Alt+X,R,U), its default keybinding (Shift+Alt+C), or the Quick Action and Refactoring menu (Shift+Alt+Q).

You can modify the file name for the new class you want it to differ from the class name:

Press OK, and you're done. Visual Assist infers the type of the constructor parameters to create member variables and initialize them automatically:

Member variables will derive appropriate names from the given parameter list. You can use the rename command on the variables created from constants, to easily give descriptive names:

You can also invoke the command when you don't pass parameters. The command works both with or without parenthesis:

Foo *pFoo = new Foo();

or

Foo *pFoo = new Foo;

You can edit the refactoring snippets for Create from Usage (for class) to modify the content and the format of the created class. Special reserved strings are available for these VA Snippets.

Create Class Member

Quickly add a helper method or state variable to a class while working elsewhere in that class. Visual Assist distinguishes unknown methods from unknown variables by looking for parentheses following the symbol name.

Access Create from Usage from the VAssistX menu (Alt+X,R,U), its default keybinding (Shift+Alt+C), or the Quick Action and Refactoring menu (Shift+Alt+Q).

Visual Assist uses the same language-typing rules as the compiler to infer the correct type.

The variable appears wherever specified.

Create from Usage can also create methods in a class. 

The default behavior is to throw a runtime exception indicating the method is not implemented. You can change the default code by editing the Refactor Create Implementation VA Snippet for the appropriate programming language.

Create Parameter to Function/Method

Parameterize global functions or static methods to encourage re-use of utility code. 

You can designate unrecognized symbols as parameters and Create from Usage will generate code in the appropriate method declaration and definition.

Create Enum Value

Define a new enum value from a call site. Define from an assignment, comparison, or switch statement (or other construct in which the type of the unknown symbol can be inferred as an enum).

C++ enum values to be inserted from a call site must use the Microsoft-specific syntax qualifier::name. This indicates to Visual Assist that you are adding an enum value rather than introducing a new variable of the enum type.

Create Global Function

Create from Usage on an unknown function outside of a class scope will create a global function.

Create Local or Global Variables

When performing Create from Usage on an unknown variable outside of class scope, you are given a choice of creating a parameter to the containing function, or creating a local or global variable.

Formatting

Control the appearance of parameters (particularly white space) using the Refactor Create Implementation VA Snippet of each language. Edit the Refactor Create From Usage Method Body VA Snippet of each language to specify the default code to be placed in the created method. For instance, you may wish to write code that does not compile to force you to go back and write the implementation. 

While Visual Studio provides similar functionality for C#, users of C# may still wish to employ the Create from Usage feature of Visual Assist to take advantage of advanced formatting options.

If Visual Assist is unable to infer the type of the variable or method being created, the placeholder "UnknownType" will be inserted.

Registry Settings

Value Name Meaning
ClassMemberNamingBehavior Adjust prefix of member name for Create from Usage (class)