PC Review


Reply
Thread Tools Rate Thread

Confused about generics ...

 
 
shapper
Guest
Posts: n/a
 
      6th Oct 2008
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
 
Reply With Quote
 
 
 
 
Marc Gravell
Guest
Posts: n/a
 
      13th Oct 2008
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
 
Reply With Quote
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Generics and comparison (follow on from my previous "Generics and collections" thread) Martin Robins Microsoft Dot NET 7 5th Apr 2008 03:36 PM
Generics and comparison (follow on from my previous "Generics and collections" thread) Martin Robins Microsoft C# .NET 7 5th Apr 2008 03:36 PM
confused about generics and abstract classes herpers@wiso.uni-koeln.de Microsoft C# .NET 13 12th May 2006 03:46 PM
Generics C# VS Generics java VS Template C++ Locia Microsoft C# .NET 2 21st Sep 2005 08:03 PM
Generics - A question on generics - delegates - runtime binding. =?Utf-8?B?YmlndGV4YW4=?= Microsoft C# .NET 10 26th Jul 2005 09:00 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 07:10 AM.