lundi 20 février 2017

C# change Func generic type at runtime [on hold]

How i can change Func<int,T,int> type to Func<int,G1,int> in runtime, in case:

public
class MyClass<G, G1>
{
    int call = 0;

    public int method()
    {
        int a, b = 0;

        a = by_method<G>(private_method);
        b = by_method<G>(private_method);

        return a + b;
    }

    private int by_method<T>(Func<int, T, int> func)
    {
        if (call == 0)
        {
            call++;
            return func(0, default(T));
        }
        else
        {
            //cast Func<int,T,int> to Func<int,G1,int>
            return by_method<G1>(func);
        }
    }

    private int private_method<T>(int a, T instance)
    {
        return 0;
    }
}

I must add some text, because stackoverflow can't approve this question without this. So, this is a little text for this reasons.





Aucun commentaire:

Enregistrer un commentaire