Re: Pass type to method to allow create and method invocation?

Tech Tip: Click here to run a free scan for Windows Errors and optimize PC performance




On Aug 17, 9:06 pm, "Grant Schenck" <schen...@xxxxxxxxxxxxx> wrote:

Instead of passing a Type to DoExecute() and creating an instance
inside the method, wouldn't it make more sense to create an instance
outside the method and pass that?

No because the class needs to be able to create instances of the specified
type in response to external events (in this case, phone calls.)

It still sounds like you could use type safe instance creation, like:

DoExecute<TScriptCall>() where TScriptCall : ScriptCallBase {
TScriptCall scriptCall = new TScriptCall();
scriptCall.OverriddenMethod();
}

....and invoke it thusly:

DoExecute<ScriptCallInbound>();

My point is that compile-time type safety in my experience usually
saves nine.

.