Quando si prepara a TryInvokeMember () di DynamicObject (), come scegliere un sovraccarico corretto per invocare?

StackOverflow https://stackoverflow.com/questions/5846107

Domanda

Come implementeresti un algoritmo per scegliere il sovraccarico del metodo corretto, quando si sfugge al seguente metodo su DynamicObject?

bool TryInvokeMember(InvokeMemberBinder binder, object[] args, out object result)
È stato utile?

Soluzione

If this overload issue is due to forwarding to statically implemented methods. A solution could be to just let the dlr do the work for you. Open source Dynamitey has a static method that creates all the dlr binding code, caches appropriately and then invokes it and the dlr binder does overload resolution. example. This example handles named/optional params and inferred generics in the overload resolution, however DynamicObject does not expose explict generics or ref out params in the invocation.

Altri suggerimenti

It's not straightforward as you have to take into account things like implicit type conversion and variable length parameters (which must be mapped to arrays).

The MethodCallResolver class in the Zentrum framework provides an example of how to find a matching method.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top