Visual Studio Code Snippets are small blocks of reusable code that can be inserted into a code file using a context menu or set of key-presses. Code Snippets can be used to quickly create commonly-used code structures such as methods or properties, reducing the amount of code that developers must type to do so.
Code Snippets consist of a block of standardised text, and small editable sections. When a snippet is first entered, the editable sections are highlighted and the user can overtype the values to customise the code snippet. The developer can move between the editable elements of the snippet by pressing
Tab, and press
Esc to finish editing.
Executing Code Snippets
Using the keyboard
To execute a Code Snippet, the developer types the name of the code snippet (e.g.
prop) and presses
Tab twice. Visual Studio then executes the snippet and places it at the current location.
Resharper can alter the standard keyboard shortcuts. If you are using Resharper then You must press
Ctrl-J, then type the code snippet name. The other keyboard shortcuts still work.
Using the mouse
To execute the code snippet, the developer right-clicks at the appropriate place in the code file and selects
Insert Code Snippet.... The available code snippets are listed in a folder-style structure. The developer can double-click on the required Code Snippet and fill out the editable elements of the snippet by pressing
Code Snippets and the Vault Application Framework
When developing applications using the Vault Application Framework it is common to create methods that are executed in response to various events within the vault, such as an object reaching a state in a workflow, or a property value requiring validation. Attributes are used to ensure that the Vault Application Framework knows which methods need to be executed at what time. These attributes often require the following method to have a specific signature in order to function; if the method does not match the expected signature then it will not be invoked.
The Vault Application Framework Attributes page details the attributes and their expected method signature, if appropriate.
Code Snippets can be used to automatically generate class members (methods and properties) with the correct structure and signatures, reducing development time.
Contributing to the Code Snippets
To contribute additional code snippets or to fix issues with existing code snippets, please visit the GitHub Samples and Libraries repository, fork the repository, make the required changes, then submit a pull request. GitHub has further information on forking and pull requests.
Available Code Snippets
The following code snippets exist. Once the snippets are installed, simply type their name within a code file, select the snippet, and press
MFVAFPropertyAutomaticNumbercreates a code snippet for PropertyAutomaticNumberingAttribute.
MFVAFPropertyCustomValuecreates a code snippet for PropertyCustomValueAttribute.
MFVAFPropertyValidationcreates a code snippet for PropertyValueValidationAttribute.
Vault Extension Methods
MFVAFVaultExtensionMethodcreates a code snippet for VaultExtensionMethodAttribute.
MFVAFStateActioncreates a code snippet for StateActionAttribute.
MFVAFStatePreConditioncreates a code snippet for StatePreConditionsAttribute.
MFVAFStatePostConditioncreates a code snippet for StatePostConditionsAttribute.
MFVAFAutomaticStateTransitionTriggercreates a code snippet for AutomaticStateTransitionTriggerAttribute.
MFVAFEventHandlercreates a code snippet for EventHandlerAttribute.
Vault Structural Elements (MFIdentifiers)
MFVAFClassGroupIdentifiercreates a code snippet for a MFIdentifier with a
MFVAFClassIdentifiercreates a code snippet for a MFIdentifier with a
MFVAFObjectTypeIdentifiercreates a code snippet for a MFIdentifier with a
MFVAFValueListIdentifiercreates a code snippet for a MFIdentifier with a
MFVAFValueListItemIdentifiercreates a code snippet for a MFIdentifier with a
MFVAFNamedAccessControlListIdentifiercreates a code snippet for a MFIdentifier with a
MFVAFUserGroupIdentifiercreates a code snippet for a MFIdentifier with a
MFVAFPropertyDefinitionIdentifiercreates a code snippet for a MFIdentifier with a
MFVAFWorkflowIdentifiercreates a code snippet for a MFIdentifier with a
MFVAFWorkflowStateIdentifiercreates a code snippet for a MFIdentifier with a
MFVAFWorkflowStateTransitionIdentifiercreates a code snippet for a MFIdentifier with a
MFVAFViewIdentifiercreates a code snippet for a MFIdentifier with a
MFVAFConfigurationcreates a code snippet for a property with a
Installing the Vault Application Framework Code Snippets
Installing using the Visual Studio Template Package
Code Snippets are included in the M-Files Online Visual Studio Template Package. Installing this package also installs the code snippets listed here.
The package can be uninstalled by opening Visual Studio, clicking
Extensions and Updates..., as with other installed extensions.
Downloading the raw snippet files (not recommended)
The raw snippet files are available for download within our GitHub Samples and Libraries repository. To install the snippets manually:
- Download the
- Open Visual Studio.
- Click the
Toolsmenu item and select
Code Snippets Manager.
Addand locate the downloaded