Note that there are some explanatory texts on larger screens.

plurals
  1. POPassing delegate with template args as parameter
    text
    copied!<p>I'm struggling with the code below. </p> <p>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. </p> <p>The problem is that the Filter delegate must be able to accept a Template type as argument, and the compiler is complaining that the <strong>parameters to the Find method doesn't match</strong>. The problem happens inside the method FindItems when I call Find. </p> <p>Any ideas? Many thanks</p> <pre><code> delegate bool FindFilter&lt;T_Item&gt;(T_Item item); private List&lt;MailItem&gt; Find&lt;T_Item, T_Adaptor&gt;(T_Adaptor adaptor, MailItemId mailId, FindFilter filter) { List&lt;T_Item&gt; tempList = ((List&lt;T_Item&gt;)(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&lt;T_Item&gt; Items = tempList.FindAll( filter() ); List&lt;MailItem&gt; mailItems = new List&lt;MailItem&gt;(); foreach (T_Item itm in Items) mailItems.Add(itm as MailItem); return mailItems; } private static bool FindAssignedItemsOnly&lt;T_Item&gt;(T_Item itm) { MailItem mi = itm as MailItem; if (mi == null) return false; return (mi.StateInd.Code == StateInd.ASSIGNED); } public List&lt;MailItem&gt; FindItems(MailItemId itemId, string mailCategoryCd) { List&lt;MailItem&gt; mailItems = new List&lt;MailItem&gt;(); FindFilter&lt;MailItem&gt; f = FindAssignedItemsOnly; // Problem happens in the line below mailItems = Find&lt;Letter, BasicItemAdapter&gt;(new LetterItemAdapter(), itemId, f); return mailItems; } </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload