c# - How to call a function dynamically based on an object type -
Based on the type of parameter passed in the parameters, I am looking for a great way to call the function .
In other words, I want the EntryPoint
method to dynamically call the appropriate myFunc method (below) depending on the type of template parameter (below) I am
Public Zero EntryPoint (object template) {missingMethod (template); // This is the code in question which myFunc} should call private myfunc {TemplateA template} {doSomething (template); } Private Zero myFunc (TemplateB Template) {doSomethingElse (template); } Private Zero myFunc (Object templates) {New NotImplementedException Throwing (template.GetType ()); }
three options:
- Wait for C # 4 and use dynamic typing (possibly not in your case)
Comments
Post a Comment