vendredi 11 août 2017

How can I return an empty Enumerable for a given type passed as parameter to a function? [duplicate]

This question already has an answer here:

I have been trying to implement a load method for a thin NHibernate layer I am writing for data access purposes. The part where I am stuck is to how to return an empty IEnumerable in case I receive a null Icriteria while searching.

I tried using Enumerable.Empty(), however the error I get is "T is a variable but used like a type." I understand the error, but not able to find any workarounds. Can someone please suggest one for this scenario ? I want to create an empty IEnumearable when the type is being passed as parameter.

 public IEnumerable load(Type T, ICriteria c)
    {
        return c != null ? c.List() : Enumerable.Empty<T>();

    }





Aucun commentaire:

Enregistrer un commentaire