Weaving argument checks
With the Catel.Fody plugin, it is possible to automatically weave a method implementation with its own argument check operations declared via attributes.
Usage example
The following method definition:
public void DoSomething([NotNullOrEmpty] string myString. [NotNull] object myObject) { }
Will be weaved into:
public void DoSomething(string myString, object myObject) { Argument.IsNotNullOrEmpty("myString", myString); Argument.IsNotNull("myObject", myObject); }
In the background, Catel.Fody will handle the following workflow:
- Find all types in the assembly
- Find all method of each type
- Find all annotated method parameter of each method
- Insert as first instructions of the method body the calls to Argument check corresponding methods.
Available argument check Catel.Fody attributes
The following table shows the available argument check attributes and its corresponding Argument class checks method:
Fody attribute | Argument method |
---|---|
NotNull | Argument.IsNotNull |
NotNullOrEmptyArray | Argument.IsNotNullOrEmptyArray |
NotNullOrEmpty | Argument.IsNotNullOrEmpty |
NotNullOrWhitespace | Argument.IsNotNullOrWhitespace |
Match | Argument.IsMatch |
NotMatch | Argument.IsNotMatch |
NotOutOfRange | Argument.IsNotOutOfRange |
Maximum | Argument.IsMaximum |
Minimal | Argument.IsMinimal |
OfType | Argument.IsOfType |
ImplementsInterface | Argument.ImplementsInterface |
InheritsFromAttribute | Argument.InheritsFrom |