mercredi 13 janvier 2021

nested delegate call of unknown type at compile time

Supose I have a 2 Delegates, and i donw know the "TUnknown" type at compile time

  Func<T, TUnknown> delegate1;
  Func<TUnknown, object> delegate2;

how do I create a lambda statment like this:

(T t) => ((Func<TUnknown, object>)delegate2)(((Func<T, TUnknown>)delegate1)(t))

I was able to do it using DynamicInvoke like this:

(T t) => delegate2.DynamicInvoke(delegate1.DynamicInvoke(t));

But it is slow. There is a better solution ?





Aucun commentaire:

Enregistrer un commentaire