Generic Class Receiving a Generic List>?

Asked

Viewed 178 times

2

In c# I can implement a generic class where 1 of the received attributes is a List<>? object something like:

public class Negocio<TEnt, TDto, TDao, TList<coisas>>

So you can call her that...

Negocio<Entidade, Dto, Dao, TList<minhascoisas>> meunegocio = new Negocio<Entidade, Dto, Dao, TList<minhascoisas>>()

I’m trying this because I’m actually generalizing a series of classes with everything similar, except for a set of properties that can vary even in quantity between them. As I do not know how many properties will be (can be zero to five) I thought of passing them as a list.

Is that possible? Can anyone say how? I tried as in this example but the syntax error.

  • There must be, but we need more details.

1 answer

3


There is, just use it type parameter constraint. Placed object in the generic list type, change to your need.

Example:

public class Negocio<TEnt, TDto, TDao, TList>() where TList : IList<object>
{
}
  • Thanks @Murarialex ! Saved my life, rsrsrs.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.