Is there a pattern that I could apply to refactor this code? The only difference between the two methods is that that one method takes an extra parameter and passes it to the delegate?
I found out that delegates cannot take overloaded method signatures. How could I add one more level of indirection? :)
public static void ProcessFolder(
ProcessFolderDelegate processFolderDelegate
)
{
using (var esb = ExchangeService.GetExchangeServiceBinding())
{
var contactFolder = FolderService.GetPublicFolder(esb,
Properties.Settings.Default.ExchangePublicFolderName);
processFolderDelegate(esb, contactFolder);
}
}
public static void ProcessContact(
ProcessContactDelegate processContactDelegate,
Contact contact //extra param
)
{
using (var esb = ExchangeService.GetExchangeServiceBinding())
{
var contactFolder = FolderService.GetPublicFolder(esb,
Properties.Settings.Default.ExchangePublicFolderName);
processContactDelegate(esb, contactFolder, contact); //extra param
}
}