lundi 17 décembre 2018

Object does not match target type reflection

I'm building a small framework for my WPF application. I have the following view model:

public class MyViewModel : ICanHandle<MyCommand, CanHandleMyCommand> {}

In the background when my ExtendedEventAggregator publishes a command of type MyCommand, it will look up all subscribers of this command, and find the implemented interface to see if it can handle this.

public ExecuteStrategy(MethodInfo command, Type canExecuteType)
{
   Command = command;
   CanExecuteType = canExecuteType;
   CanExecute = CanExecuteType.GetMethod("CanExecute");
}

public void Execute(object message)
{
   CanExecute.Invoke(CanExecuteType, new[] { message });
}

Running the Execute method will result in an exception saying object does not match target type. I thought the CanExecuteType was the type associated with this method?

What am I missing here?





Aucun commentaire:

Enregistrer un commentaire