mercredi 22 novembre 2017

C# : Create a Tuple from a generic type using reflection

I would like to be able to pass a Tuple to the following method, however I can't since I have to instantiate it.

    public List<T> SelectFromDataBase<T>() where T : new()
    {
        var ls = new List<T>();

        // highly simplified here
        T t = new T();
        t.GetType().GetProperty("ClientName").SetValue(t, "Mr Smith");

        ls.Add(t);

        return ls;
    }

Is there any solution ?





Aucun commentaire:

Enregistrer un commentaire