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)
< Personally, I tried to think about an alternative design, which it did not want in the first place, but obviously it is not always realistic.


Comments

Popular posts from this blog

c# - ListView onScroll event -

PHP - get image from byte array -

Linux Terminal Problem with Non-Canonical Terminal I/O app -