M
mike
I've got two methods that do basically the same thing, just with
different parameters. See the method below.
public IEnumerable<FaqListItem> GetItemsOfCategory(string category)
{
IEnumerable<FaqListItem> itemsOfCategory =
from item in items.GetItems()
where item.Category == category
select new FaqListItem
{
Title = item.Title,
Question=item.Question,
Answer=item.Answer,
Category=item.Category
};
return itemsOfCategory;
}
I have also written a GetItemsOfTitle method that uses the item's
title instead. I'm looking for .NET 3.0 / 3.5 ways in which I can
refactor these methods into one into which I can pass in the field
name as well as the method. I think I've seen something like this
using Func<> or something but I'm not sure anymore.
I'm also interested in finding out if I can simplify my select as item
is of the same type as what I'm generating.
Thanks
Mike
different parameters. See the method below.
public IEnumerable<FaqListItem> GetItemsOfCategory(string category)
{
IEnumerable<FaqListItem> itemsOfCategory =
from item in items.GetItems()
where item.Category == category
select new FaqListItem
{
Title = item.Title,
Question=item.Question,
Answer=item.Answer,
Category=item.Category
};
return itemsOfCategory;
}
I have also written a GetItemsOfTitle method that uses the item's
title instead. I'm looking for .NET 3.0 / 3.5 ways in which I can
refactor these methods into one into which I can pass in the field
name as well as the method. I think I've seen something like this
using Func<> or something but I'm not sure anymore.
I'm also interested in finding out if I can simplify my select as item
is of the same type as what I'm generating.
Thanks
Mike