Skip to content

DamianReeves/Commander.Fody

Repository files navigation

This is an add-in for Fody

Injects ICommand properties and implementations for use in MVVM applications.

Introduction to Fody

Your Code

public class SurveyViewModel
{
    [OnCommandCanExecute("SubmitCommand")]
    public bool CanSubmit()
    {
        ... 
    }
    [OnCommand("SubmitCommand")]
    public void OnSubmit(){
        ...
    }        
}

With a command implementation in assembly like:

public class DelegateCommand : ICommand
{
    ...

    public DelegateCommand(Action execute):this(execute, null)
    {        
    }

    public DelegateCommand(Action execute, Func<bool> canExecute)
    {
        ...
    }

    public void Execute(object parameter)
    {
        ...
    }

    public bool CanExecute(object parameter)
    {
        ...
    }    
}

What Gets Compiled

public class SurveyViewModel
{
    SurveyViewModel()
    {
        <Commander_Fody>InitializeCommands();            
    }
    public ICommand SubmitCommand {get;set;}

    public bool CanSubmit(){ 
        ...
    }
    public void OnSubmit(){
        ...
    }   

    private void <Commander_Fody>InitializeCommands()
    {
        if (this.SubmitCommand == null)
        {
            this.SubmitCommand = new DelegateCommand(new Action(this.OnSubmit), new Func<bool>(this.CanSubmit));
        }
    }
}

What it does

TODO

Icon

About

A Fody weaver for ICommand invocation and implementation.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published