jeudi 27 juin 2019

Create generic type from IEnumerable

I'm trying to create a generic type from an IEnumerable

Tried something like this

var generic = typeof(IEnumerable<>).MakeGenericType(property.PropertyType);

Activator.CreateInstance(generic , true)

But I get

"Cannot create an instance of an interface" and the stack points to this instance when it tries to create one.

public class Administration
{
     private IList<Student> _student;
     public IEnumerable<Student> Students { get => _student; }

     private Administration() { }
}

public class Student 
{
     private Student () {} 
} 





Aucun commentaire:

Enregistrer un commentaire