Dotnet logo

.NET Tools

Essential productivity kit for .NET and game developers


CatelR# – a niche plugin for the Catel framework

Most ReSharper plugins provide general-purpose services – spell checking, style enforcement, unit testing, code generation or context actions for XAML, string manipulation or code quality. The focus is wide, either concentrating on multiple file types or multiple analyses.

The CatelR# ReSharper plugin takes a different approach, and has a very narrow focus. It provides context actions and analyses specifically for users of the Catel framework.

Catel is a framework with a focus on MVVM based applications. It provides multiple services to the application developer, including an IoC container, validation, message mediation and argument validation. It also provides MVVM services, such as view model support, commands and behaviours. Check out the extensive documentation for more details of the framework itself.

The plugin’s aim is to streamline development with the framework, trying to make it as easy as possible to get the most out it. For example, when creating a ViewModel, Model or data object class, CatelR# offers a context action on the class declaration to make it derive from Catel’s ViewModelBase, ModelBase or DataObjectBase classes, automatically inserting the correct using statements.

Context action to derive from Catel base objects

And these options only show up once you’ve added assembly or NuGet references to Catel.Core and Catel.MVVM.

Similarly, it offers context actions to convert a normal auto-property into a Catel property, similar to XAML’s DependencyProperty, which can be used for data binding. Optionally, you can also have it create a method to be used when the value changes.

Context action to convert auto-property to Catel property

Resulting in generated code that looks like this:

Example of generated Catel property

The generated NameProperty field also has a context action to include or exclude it from serialisation, which alters the parameters to the RegisterProperty method, and another that will convert it back into an auto-property.

And this is made even easier using the Generate Code menu, which allows converting multiple properties at once.

Generate multiple Catel properties at once

A similar code generation workflow is provided that makes it very easy to map between a model and a view model. The view model creates a property that holds the model instance. As long as this property is marked with the ModelAttribute, CatelR# now knows the type of the model, and can generate matching properties in the view model, saving a lot of work. See this blog post for more details.

The other main feature offered by the plugin is to add argument checking, using the framework’s own methods. This adds context actions to method parameters. For strings, you get to check for null/empty or null/empty/whitespace.

Add argument check for parameter

For objects you can assert that it is a specific type or implements a specific interface, and for integers, you get a choice for minimum, maximum or within range. When you select one of these options, CatelR# uses ReSharper’s LiveTemplate hotspots to allow for editing the values, which ReSharper automatically copies to the xml documentation that CatelR# also creates.

Argument check with hotspot editing

This plugin provides some very useful features for the users of the Catel framework. The focus is refreshingly narrow and very much aimed at reducing friction for Catel users – quickly implementing the patterns and code necessary to use the framework, allowing the user to concentrate on adding the business value. This is a fantastic approach for a ReSharper plugin, and one that could be used to great effect by other library developers.

Catel and CatelR# are both open source projects, hosted on CodePlex. The Catel framework can be installed via NuGet, and the ReSharper plugin is available on the CodePlex download page.

image description

Discover more