I've got a class with many string arrays. I'd like to have one generic function which can get me a unique List<string>
for a given property. Example:
public class Zoo
{
string Name { get; set;}
string[] Animals { get; set;}
string[] Zookeepers { get; set;}
string[] Vendors { get; set;}
}
I'd like to have a generic function that will get me a distinct List<string>
of Animals in List? I want this to be generic, so I can also get a distinct list of Zookeepers and Vendors.
I've been trying this, but it doesn't compile:
public static List<string> GetExtendedList(Func<Zoo, string[]> filter)
{
var Zoos = QueryZoos(HttpContext.Current);
return Zoos.Where(z => z.Type == "Active")
.SelectMany(filter)
.Distinct()
.OrderBy(s => s);
}
Note: this is related to two questions I've asked before, but I'm having trouble merging the information. I previously asked how to query using SelectMany (SO 1229897) and separately asked how to write a generic function which gets a list using Select rather than SelectMany (SO 1278989).