Fody is a Nuget package that allows you to decorate your code with attributes and from them generate code automatically using IL injection.
From the official project:
Manipulating the IL of an assembly as part of a build requires a significant amount of plumbing code. This plumbing code involves knowledge of both the MSBuild and Visual Studio APIs. Fody attempts to eliminate that plumbing code using an extensible add-in model.
It is also the name of this cute little bird. :)
Fody can be found in Github. It has loads of modules and you can create your own modules. There are some particularly interesting modules such as the following.
PropertyChanged
Rather than doing this:
- public class Foo : INotifyPropertyChanged
- {
- private string name;
- public string Name
- {
- get { return name; }
- set
- {
- if (name != value)
- {
- name = value;
- NotifyPropertyChange();
- }
- }
- }
-
- public event PropertyChangedEventHandler PropertyChanged;
-
- public void NotifyPropertyChange([CallerMemberName] string propertyName = null)
- {
- if (PropertyChanged != null)
- {
- PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
- }
- }
- }
You can simply build it with this:
- [PropertyChanged.ImplementPropertyChanged]
- public class Foo
- {
- public string Name { get; set; }
- }
Fody has also other modules such as:
Among others.