We as developers of Catel are a huge fan of Resharper. And, of course we are also a big fan of Catel. One of the developers, Alex, came up with a great idea (and implementation) of a plugin for Resharper which makes it much easier to write Catel specific features.
Before we start, you can find the installer here.
Checking arguments of a method
If you are not using the Argument class, you are definitely missing something! It allows you to check for a method input and make sure it is valid. So, instead of writing this:
public void DoSomething(string myInput)
{
if (string.IsNullOrWhitespace(myInput)
{
Log.Error("Argument 'myInput' cannot be null or whitespace");
throw new ArgumentException("Argument 'myInput' cannot be null or whitespace", "myInput");
}
// custom logic
}
You can write this:
public void DoSomething(string myInput)
{
Argument.IsNotNullOrWhitespace("myInput", myInput);
// custom logic
}
However, when you are writing lots of code, then even this piece of code can be too much. Thanks to the Catel.Resharper plugin, it is possible to select the argument (in this case myInput), hit ALT + Enter and generate the code, just like the video below:
Converting regular properties into Catel properties
Catel is extremely powerful, but sometimes the property definitions are lots of work to write down. The code snippets already make your life much easier, but with the Catel.Resharper plugin it might be even easier. You can simply write this code:
public class Person : DataObjectBase<Person>
{
public string FirstName { get; set; }
public string MiddleName { get; set; }
public string LastName { get; set; }
}
Then hit ALT + Enter and turn properties into Catel properties, which will result in this class:
public class Person : DataObjectBase<Person>
{
/// <summary>
/// Gets or sets the first name.
/// </summary>
public string FirstName
{
get { return GetValue<string>(FirstNameProperty); }
set { SetValue(FirstNameProperty, value); }
}
/// <summary>
/// Register the FirstName property so it is known in the class.
/// </summary>
public static readonly PropertyData FirstNameProperty = RegisterProperty("FirstName", typeof(string));
/// <summary>
/// Gets or sets the middle name.
/// </summary>
public string MiddleName
{
get { return GetValue<string>(MiddleNameProperty); }
set { SetValue(MiddleNameProperty, value); }
}
/// <summary>
/// Register the MiddleName property so it is known in the class.
/// </summary>
public static readonly PropertyData MiddleNameProperty = RegisterProperty("MiddleName", typeof(string));
/// <summary>
/// Gets or sets the last name.
/// </summary>
public string LastName
{
get { return GetValue<string>(LastNameProperty); }
set { SetValue(LastNameProperty, value); }
}
/// <summary>
/// Register the LastName property so it is known in the class.
/// </summary>
public static readonly PropertyData LastNameProperty = RegisterProperty("LastName", typeof(string));
}