Confused about generics ...


S

shapper

Hello,

I have the following method:

public static IEnumerable GetRoles(CultureInfo culture, bool open)
{
switch (culture.TwoLetterISOLanguageName.ToLower()) {
case "en":
return new[] {
new { Name = Role.Administrator, Description =
"Administrador", open = false },
new { Name = Role.Collaborator, Description =
"Colaborador", open = true }
}.OrderBy(r => r.Description);
}
return null;
}

Basically, what I would like to do, but not knowing if possible is:
- Create the items in a generic way (Not creating a class for this):
new { Name = Role.Administrator, Description = "Administrador", open
= false }

- Being able to use Linq on the result:
GetRoles(new CultureInfo("en-GB" , true)).Where(r => r.open = false)

I think I will need always to use List<RoleClass> right?

Thanks,
Miguel
 
Ad

Advertisements

M

Marc Gravell

It will be very hard for a downstream consumer to know what your data
looks like, and hard to test. I would create a Role class that
represents a role. However, you don't need to switch to List<Role> -
IEnumerable<Role> would do.

Btw - this has got nothing to do with generics; just anonymous types.

Marc
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads

confusion about generics 2
confused about generics and abstract classes 13
Generics confusion 2
About Generics 1
About generics 9
about generics 8
Confused about reflection 8
Confused about casting. 3

Top