CodePaste Logo
New Snippet New Snippet Recent Snippets Recent Snippets My Snippets My Snippets Web Code Search Snippets Search
Sign inor Register
Language: C#

Double dispatch for Parameters

167 Views
Copy Code Show/Hide Line Numbers
public class StoredProcedureGateway : IExternalSystemGateway {
  public object Call(string procedure, object[] params) {
    // call sproc
  }
}
 
public class SomeStoredProcedureParameters : IIssueExternalCalls {
  public string SomeString;
  public int SomeInt; 
  public object IssueWith(IExternalSystemGateway gateway) {
    gateway.Call("Some_StoredProcedure", SomeString, SomeInt);
  }
}
 
public class OtherStoredProcedureParameters : IIssueExternalCalls {
  public string OtherString1;
  public string OtherString2; 
  public object IssueWith(IExternalSystemGateway gateway) {
    gateway.Call("Other_StoredProcedure", OtherString1, OtherString2);
  }
}
 
public interface IIssueExternalCalls {
  object IssueWith(IExternalSystemGateway gateway);
}
 
 
///////////////////////////
//Usage
///////////////////////////
public class MainLoop() {
  readonly IExternalSystemGateway gateway;
  public Run(params IIssueExternalCalls[] calls) {
    foreach(var call in calls)
       call.IssueWith(gateway);
  }
by togakangaroo
  August 30, 2010 @ 10:59am
Tags:

Add a comment


Report Abuse
brought to you by:
West Wind Techologies



If you find this site useful and use it frequently please consider making a donation to support this free service.
Donate