我想在具有抽象类类型的对象上调用子类实现。然而,这并不像我想象的那样工作。有没有办法做到这一点,不需要我在第二个 switch 语句中在类型之间切换?或者 C# 不允许这种类型的行为?
调用它的代码:
AbstractParentType wfp;
//Switch on diagram type and select processor
switch (qi.DIAGRAMTYPE)
{
case 1:
wfp = new T1(notifications);
break;
case 2:
wfp = new T2(notifications);
break;
case 3:
wfp = new T3(notifications);
break;
default:
throw new Exception("Diagramtype not implemented");
}
bool result = false;
//Switch on action type
switch (qi.Type)
{
case (int)WorkflowActionType.BelItem:
//Do some case specific stuff here
...
//Call method
result = wfp.Meth1();
break;
... (a bunch of cases) ...
case (int)WorkflowActionType.WordDocument: …Run Code Online (Sandbox Code Playgroud)