I’m struggling with the code below.
I have a method Find, which for me is generic in terms I can use it for different type deriving from the same base class. Inside this method I used to have a delegate passed to the FindAll call. I removed this delegate and I’m trying to pass it as parameter, so more methods can use the Find method with different filtering criteria.
The problem is that the Filter delegate must be able to accept a Template type as argument, and the compiler is complaining that the parameters to the Find method doesn’t match. The problem happens inside the method FindItems when I call Find.
Any ideas? Many thanks
delegate bool FindFilter<T_Item>(T_Item item);
private List<MailItem> Find<T_Item, T_Adaptor>(T_Adaptor adaptor, MailItemId mailId, FindFilter filter)
{
List<T_Item> tempList = ((List<T_Item>)(typeof(T_Adaptor).InvokeMember(
"Load",
BindingFlags.DeclaredOnly | BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.InvokeMethod,
null, adaptor,
new Object[] { null, mailId, null })));
totalItemsFound = tempList.Count;
List<T_Item> Items = tempList.FindAll(
filter()
);
List<MailItem> mailItems = new List<MailItem>();
foreach (T_Item itm in Items)
mailItems.Add(itm as MailItem);
return mailItems;
}
private static bool FindAssignedItemsOnly<T_Item>(T_Item itm)
{
MailItem mi = itm as MailItem;
if (mi == null) return false;
return (mi.StateInd.Code == StateInd.ASSIGNED);
}
public List<MailItem> FindItems(MailItemId itemId, string mailCategoryCd)
{
List<MailItem> mailItems = new List<MailItem>();
FindFilter<MailItem> f = FindAssignedItemsOnly;
// Problem happens in the line below
mailItems = Find<Letter, BasicItemAdapter>(new LetterItemAdapter(), itemId, f);
return mailItems;
}
I made some changes:
to
FindItems, changeftoFindFilter<BasicItem>:and to
Find, use theFindFiltergeneric type:and changed the main search:
and it compiles; obviously I can’t test it since I had to invent a lot of code…