Git Product home page Git Product logo

commander.fody's Introduction

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

commander.fody's People

Contributors

codejr avatar damianreeves avatar slodge avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

commander.fody's Issues

MVVMCross InvalidProgramException: Missing or incorrect header for method add_CanExecuteChanged

Hi, upon binding commands with MVVMCross, there is a Warning below, could you please have a look?

MvxBind:Error: 0.94 Problem seen during binding execution for binding Click for SubmitCommand - problem TargetInvocationException: Exception has been thrown by the target of an invocation.
at System.Reflection.MonoMethod.Invoke (System.Object obj, BindingFlags invokeAttr, System.Reflection.Binder binder, System.Object[] parameters, System.Globalization.CultureInfo culture) [0x00050] in /Users/builder/data/lanes/2970/46c3f7e0/source/mono/mcs/class/corlib/System.Reflection/MonoMethod.cs:303
at System.Reflection.MethodBase.Invoke (System.Object obj, System.Object[] parameters) [0x00000] in /Users/builder/data/lanes/2970/46c3f7e0/source/mono/external/referencesource/mscorlib/system/reflection/methodbase.cs:277
at MvvmCross.Platform.WeakSubscription.MvxWeakEventSubscription`2[TSource,TEventArgs].AddEventHandler () [0x0002c] in V:\Xamarin\MvvmCross\MvvmCross\Platform\Platform\WeakSubscription\MvxWeakEventSubscription.cs:118

InnerException was InvalidProgramException: Missing or incorrect header for method add_CanExecuteChanged
at (wrapper managed-to-native) System.Reflection.MonoMethod:InternalInvoke (System.Reflection.MonoMethod,object,object[],System.Exception&)
at System.Reflection.MonoMethod.Invoke (System.Object obj, BindingFlags invokeAttr, System.Reflection.Binder binder, System.Object[] parameters, System.Globalization.CultureInfo culture) [0x00038] in /Users/builder/data/lanes/2970/46c3f7e0/source/mono/mcs/class/corlib/System.Reflection/MonoMethod.cs:295

Make the API more concise

I'm guessing the API can be made even more concise eg. can the string argument be optional, and derived from the method name? eg

[CanExecute]
public bool CanGotoTwoPage() {
...
}

[OnCommand]
public void GotoTwoPage() {
...
}

Support for Portable Libraries

Version 0.0.2.0 NuGet package doesn't support Portable Libraries.

It fails to load with the following errors:

The primary reference "Commander.Fody" could not be resolved because it has an indirect dependency on the framework assembly "mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" which could not be resolved in the currently targeted framework. ".NETPortable,Version=v4.0,Profile=Profile104". To resolve this problem, either remove the reference "Commander.Fody" or retarget your application to a framework version which contains "mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089".

The primary reference "Commander.Fody" could not be resolved because it has an indirect dependency on the framework assembly "System.Xml.Linq, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" which could not be resolved in the currently targeted framework. ".NETPortable,Version=v4.0,Profile=Profile104". To resolve this problem, either remove the reference "Commander.Fody" or retarget your application to a framework version which contains "System.Xml.Linq, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089".

The primary reference "Commander.Fody" could not be resolved because it has an indirect dependency on the framework assembly "System.Core, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" which could not be resolved in the currently targeted framework. ".NETPortable,Version=v4.0,Profile=Profile104". To resolve this problem, either remove the reference "Commander.Fody" or retarget your application to a framework version which contains "System.Core, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089".

Command not initialized in Release build

After the constructor for my ViewModel is called, I am noticing that in Debug builds, the Command that I have an attribute on is initialized and works correctly. However in a Release build, the Command is null and does nothing.

Does not work with WP

As per Issue #4 this does not work in Windows Phone.
A fix is now available for WinRT, I'm still having issues with Windows Phone testing.

Error in Portable Libraries

I'm receiving this error when trying to use Commander inside a PCL project.

Error   1   Fody/Commander: Could not resolve PresentationCore. Please ensure you are using .net 3.5 or higher.
Inner message:Can not find 'PresentationCore, Culture=neutral, PublicKeyToken=null'.
Tried:
C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETPortable\v4.0\Profile\Profile104\mscorlib.dll
C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETPortable\v4.0\Profile\Profile104\mscorlib.dll
C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETPortable\v4.0\Profile\Profile104\System.Core.dll
C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETPortable\v4.0\Profile\Profile104\System.dll
C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETPortable\v4.0\Profile\Profile104\System.Net.dll
C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETPortable\v4.0\Profile\Profile104\System.Runtime.Serialization.dll
C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETPortable\v4.0\Profile\Profile104\System.ServiceModel.dll
C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETPortable\v4.0\Profile\Profile104\System.ServiceModel.Web.dll
C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETPortable\v4.0\Profile\Profile104\System.Windows.dll
C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETPortable\v4.0\Profile\Profile104\System.Xml.dll
C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETPortable\v4.0\Profile\Profile104\System.Xml.Linq.dll
C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETPortable\v4.0\Profile\Profile104\System.Xml.Serialization.dll
Z:\Documents\workspace\NPlus1DaysOfMvvmCross\N-10-KittensDb\packages\MvvmCross.HotTuna.CrossCore.3.0.5\lib\portable-win+net45+MonoAndroid16+MonoTouch40+sl40+wp71\Cirrious.CrossCore.dll
Z:\Documents\workspace\NPlus1DaysOfMvvmCross\N-10-KittensDb\packages\MvvmCross.HotTuna.CrossCore.3.0.5\lib\portable-win+net45+MonoAndroid16+MonoTouch40+sl40+wp71\Cirrious.MvvmCross.Localization.dll
Z:\Documents\workspace\NPlus1DaysOfMvvmCross\N-10-KittensDb\packages\MvvmCross.HotTuna.Plugin.Sqlite.3.0.5\lib\portable-win+net45+MonoAndroid16+MonoTouch40+sl40+wp71\Cirrious.MvvmCross.Plugins.Sqlite.dll
Z:\Documents\workspace\NPlus1DaysOfMvvmCross\N-10-KittensDb\packages\MvvmCross.HotTuna.StarterPack.3.0.5\lib\portable-win+net45+MonoAndroid16+MonoTouch40+sl40+wp71\Cirrious.MvvmCross.dll
Z:\Documents\workspace\NPlus1DaysOfMvvmCross\N-10-KittensDb\packages\PropertyChanged.Fody.1.38.1.0\Lib\portable-net4+sl4+wp7+win8+MonoAndroid16+MonoTouch40\PropertyChanged.dll. AssemblyResolver is: InnerWeaver   KittensDb.Core

Package Manager can't find the package

... Pretty much just as it says. I've got a project using Commander which I'm trying to move to a new system, and therefore it's going looking for all the packages it needs, and Commander just throws errors whether I ask PM directly for it or I do it via the Package Manager interface.

Wha' happened?

Does not work with WP nad WinRT

I am getting "The project targets .NETCore while the file reference targets .NET Framework"

Could you make it work with WinRT and Windows Phone projects?

Update to Fody Version 2

Fody Version 2 is out and you will need to do an update for your addin to be usable with it

Specifically:

  • Update to the newest Fody.Cecil nuget
  • Change the min dependency ranged for Fody to be at least 2.0

Please ping me if u need help

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.