This repository contains the item and project templates for Catel.
The easiest way to get the code snippets is by installing them via the Visual Studio Marketplace.
Generates a static ILog
instance for the current class.
Usage: log
Output:
private static readonly ILog Log = LogManager.GetCurrentClassLogger();
Creates a new model based on the ModelBase
class.
Usage: model
Output:
[Serializable]
public class MyModel : ModelBase
{
public MyModel()
{
}
// TODO: Define your custom properties here using the 'modelprop' code snippet
}
Creates a model property for a class based on ModelBase
.
Usage: modelprop
or modelpropfody
Output:
public string FirstName
{
get { return GetValue<string>(FirstNameProperty); }
set { SetValue(FirstNameProperty, value); }
}
public static readonly PropertyData FirstNameProperty = RegisterProperty(nameof(FirstName), typeof(string), null);
Creates a model property for a class based on ModelBase
and includes a property change notification method.
Usage: modelpropchanged
or modelpropchangedfody
Output:
public string FirstName
{
get { return GetValue<string>(FirstNameProperty); }
set { SetValue(FirstNameProperty, value); }
}
public static readonly PropertyData FirstNameProperty = RegisterProperty(nameof(FirstName), typeof(string), null, (sender, e) => ((ContainingClass)sender).OnFirstNameChanged());
private void OnFirstNameChanged()
{
// TODO: Implement logic
}
Creates a view model class based on the ViewModelBase
.
Usage: vm
Output:
public class MainViewModel : ViewModelBase
{
public MainViewModel()
{
}
public override string Title { get { return "Main"; } }
// TODO: Register properties using 'vmprop'
// TODO: Register properties that represent models using 'vmpropmodel'
// TODO: Register properties that map to models using 'vmpropviewmodeltomodel'
// TODO: Register commands using 'vmcommand', 'vmcommandwithcanexecute', 'vmtaskcommand' or 'vmtaskcommandwithcanexecute'
protected override async Task InitializeAsync()
{
await base.InitializeAsync();
// TODO: Add initialization logic like subscribing to events
}
protected override async Task CloseAsync()
{
// TODO: Add uninitialization logic like unsubscribing from events
await base.CloseAsync();
}
}
Creates a view model class based on the ViewModelBase
.
Usage: vmprop
or vmpropfody
Output:
public string FirstName
{
get { return GetValue<string>(FirstNameProperty); }
set { SetValue(FirstNameProperty, value); }
}
public static readonly PropertyData FirstNameProperty = RegisterProperty(nameof(FirstName), typeof(string), null);
Creates a view model property for a class based on ViewModelBase
and includes a property change notification method.
Usage: vmpropchanged
or vmpropchangedfody
Output:
public string FirstName
{
get { return GetValue<string>(FirstNameProperty); }
set { SetValue(FirstNameProperty, value); }
}
public static readonly PropertyData FirstNameProperty = RegisterProperty(nameof(FirstName), typeof(string), null, (sender, e) => ((ContainingClass)sender).OnFirstNameChanged());
private void OnFirstNameChanged()
{
// TODO: Implement logic
}
Creates a view model property decorated with the Model
attribute.
Usage: vmpropmodel
or vmpropmodelfody
Output:
[Model]
public Human Person
{
get { return GetValue<Human>(PersonProperty); }
private set { SetValue(PersonProperty, value); }
}
public static readonly PropertyData PersonProperty = RegisterProperty(nameof(Person), typeof(Human));
Creates a view model property with a mapping to a model.
Usage: vmpropviewmodeltomodel
or vmpropviewmodeltomodelfody
Output:
[ViewModelToModel(nameof(Person))]
public string FirstName
{
get { return GetValue<string>(FirstNameProperty); }
set { SetValue(FirstNameProperty, value); }
}
public static readonly PropertyData FirstNameProperty = RegisterProperty(nameof(FirstName), typeof(string));
Creates a view model command with an execute method.
Usage: vmcommand
Output:
public Command MyCommand { get; private set; }
// TODO: Move code below to constructor
MyCommand = new Command(OnMyCommandExecute);
// TODO: Move code above to constructor
private void OnMyCommandExecute()
{
// TODO: Handle command logic here
}
Creates a view model command with an execute and can execute method.
Usage: vmcommandwithcanexecute
Output:
public Command MyCommand { get; private set; }
// TODO: Move code below to constructor
MyCommand = new Command(OnMyCommandExecute, OnMyCommandCanExecute);
// TODO: Move code above to constructor
private bool OnMyCommandCanExecute()
{
return true;
}
private void OnMyCommandExecute()
{
// TODO: Handle command logic here
}
Creates a view model task-based command with an execute method.
Usage: vmtaskcommand
Output:
public TaskCommand MyCommand { get; private set; }
// TODO: Move code below to constructor
MyCommand = new TaskCommand(OnMyCommandExecuteAsync);
// TODO: Move code above to constructor
private async Task OnMyCommandExecuteAsync()
{
// TODO: Handle command logic here
}
Creates a view model task-based command with an execute and can execute method.
Usage: vmtaskcommandwithcanexecute
Output:
public TaskCommand MyCommand { get; private set; }
// TODO: Move code below to constructor
MyCommand = new TaskCommand(OnMyCommandExecuteAsync, OnMyCommandCanExecute);
// TODO: Move code above to constructor
private bool OnMyCommandCanExecute()
{
return true;
}
private async Task OnMyCommandExecuteAsync()
{
// TODO: Handle command logic here
}
TODO: Describe all templates
Open the Visual Studio command prompt in administrator mode and run the command below:
devenv /installvstemplates
We love improvements to the templates via contributions. Below is a guide that should help you set up your environment.
- Copy the templates from the repository to VS 2019
Use the scripts - Copy templates to VS2019.ps1
script or manually copy the templates from /templates/
to %documents%\Visual Studio 2019\
.
Note that they should be put in the right directory. If you are not sure, always use the script.
- Update and test the templates
To customize the templates, edit the files in %documents%\Visual Studio 2019\Templates
.
Once customized, you can directly test them in Visual Studio.
- Copy the changes back
To copy the updated templates back to the solution, use the script scripts - Copy templates from VS2019.ps1
or manually copy the templates from %documents%\Visual Studio 2019\
to /templates/
.
- Zip the templates and copy the templates to the VSIX projects
To zip and copy the templates, use the script scripts - Copy templates to VSIX projects.ps1
- Create a PR (Pull Request) with the changes for review.