Skip to content
smackem edited this page Jun 12, 2015 · 2 revisions

NotifyPropertyChanged Injection

This is a must-have for any application that has a view model - which includes most modern GUI applications. Instead of bloating code with full property definitions like this...

public string Label
{
    get { return this.label; }
    set
    {
        if (this.label != value)
        {
            this.label = value;
            OnPropertyChanged("Label");
        }
    }
}

...Feather# allows you to achieve the same by writing the following:

[Feather(FeatherAction.NotifyPropertyChanged)]
class ViewModel : INotifyPropertyChanged
{
    public string Label { get; set }

    // ... INotifyPropertyChanged Members
}

To inject the necessary byte code, add this post-build event:

[mono] FeatherSharp.exe -npc $(TargetPath)

Feather# can even identify property dependencies by examining the call hierarchy. So if Property B depends on Property A and Property A changes, The PropertyChanged event will be raised for both properties. This even works when Property B is declared in a class that derives of the class that declares Property A. To make this work, the class to be feathered must be derived from FeatherSharp.ComponentModel.NotifyPropertyChanged.

Logging Augmentation

Effortlessly augment your log calls with type and method name of the call site. Write this:

[Feather(FeatherAction.Log)]
public class UserController
{
    public void Logon(string userName)
    {
        Log.Info("User {0} logged on", userName);
    }
}

And log this:

MyApp.Controllers.UserController::Logon - User smackem logged on

The augmented log message is raised by a static event declared by the FeatherSharp.ComponentModel.Log class, so you can subscribe to this event and use the logging backend of your choice to write out the message. To inject the necessary byte code, add this post-build event:

[mono] FeatherSharp.exe -log $(TargetPath)

Merge Assemblies

Feather# can be used to merge the assemblies referenced by the target assembly into the target assembly, similar to the ILMerge utility. It actually adds the referenced assemblies as embedded resources to the target assembly and emits a handler for the AssemblyResolve event in the target assembly's module constructor. This handler loads the embedded assemblies. This technique is described in Jeffrey Richter's book "CLR via C#".

Clone this wiki locally