In Visual Studio you can use code snippets e.g. when your are editing a class you can type ctor and the default constructor will automaticly be added to your class.
Is it possible to create a code snippet in Visual Studio, that does the following:
- Creates the get/set
Loggerproperty where the cursor is. - Adds
using Castle.Core.Logging - Lets me choose where in the list of instance variables I can place
private ILogger _logger = NullLogger.Instance;.
public class Person
{
private string name;
private int age;
public Person()
{
}
// cursor is here and you type "logger"
}
After you type logger visual Studio adds the following code:
using Castle.Core.Logging; // Added by code snippet
public class Person
{
private string name;
private ILogger _logger = NullLogger.Instance; // Added by code snippet
private int age;
public Person()
{
}
// Added by code snippet
public ILogger Logger
{
get { return _logger; }
set { _logger = value; }
}
}
There is two great tutorials here How to: Create a Basic Code Snippet & How to: Manage Code Snippets
The summary is as follows,
Happy to throw together an example if you’d like.
As I’ve created the snippet to test this, you’ll want something as follows. Self evident what you need to edit to suit your needs.