Nuget Package: Fody

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. :)

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:

  1. public class Foo : INotifyPropertyChanged    
  2. {    
  3.     private string name;    
  4.     public string Name    
  5.     {    
  6.         get { return name; }    
  7.         set    
  8.         {    
  9.             if (name != value)    
  10.             {    
  11.                 name = value;    
  12.                 NotifyPropertyChange();    
  13.             }    
  14.         }    
  15.     }    
  16.      
  17.     public event PropertyChangedEventHandler PropertyChanged;    
  18.      
  19.     public void NotifyPropertyChange([CallerMemberName] string propertyName = null)    
  20.     {    
  21.         if (PropertyChanged != null)    
  22.         {    
  23.             PropertyChanged(thisnew PropertyChangedEventArgs(propertyName));    
  24.         }    
  25.     }    
  26. }   
You can simply build it with this:
  1. [PropertyChanged.ImplementPropertyChanged]    
  2. public class Foo    
  3. {    
  4.     public string Name { getset; }    
  5. }  
Fody has also other modules such as: 

    Anotar which makes loggin easier.
    MethodTimer which makes method performance tracking easier.

Among others.


Similar Articles