vendredi 3 août 2018

C# reflection, invoke method with different parameter types

I'm looking to invoke a static method with reflection that takes a Project and 3 strings as parameters but can't find a way to achieve this. Take the below as an example

internal class PropertyActionProcessor
{
    public static async Task<Solution> ModifyNameInDto(Project project, string parentName, string oldValue, string newValue)
    {
        return new AdhocWorkspace().CurrentSolution;
    }
}

If the method just took 3 strings I could successfully invoke the "ModifyNameInDto" with the line below.

solution = await (Task<Solution>)typeof(PropertyActionProcessor).GetMethod($"Modify{propertyName}InDto").Invoke(null, new[] { parentName, itemName, newValue });

However I need to pass it a Project as well but am getting the error "no best type found for implicitly typed array". There are no overloads that can help and I can't find a solution online, is this possible and if so how could I go about it?

For anyone unfamiliar with the Project object, the same error occurs when trying to pass an int instead.





Aucun commentaire:

Enregistrer un commentaire