samedi 8 septembre 2018

C# Method invocation with parameter attributes

Lets say i have a method looking like this:

public void Time([Channel] string channel)
{
    Console.WriteLine(channel);    
}

I now want to invoke this method using:

 method?.Invoke(module, new string[] { "Test" });

The problem I'm having is that this will throw a TargetException with the message "Object does not match target type".

It works fine if i remove the parameter attribute [Channel].





Aucun commentaire:

Enregistrer un commentaire