I have c# application. I have 2 different classes (Step1.State and Step2.State) (they implement same interface called IMDP.IState) which represents application state in 2 different steps of execution of my application. I have 2 overloaded methods to update application state.
I have following code in one of my method:
Step1.State s1s = null;
Step2.State s2s = null;
Then I am casting current state depending on its type. currentState is instance of implemented interface which is received as parameter. First I am storing it in a dynamic type.
//currentState is instance of IMDP.IState interface which is
//implemented by the two states
dynamic curState=currentState;
if(curState is Step1.State)
{
s1s = (Step1.State)currentState;
curState = s1s;
}
else if (curState is Step2.State)
{
s2as = (Step2.State)currentState;
curState = s2s;
}
Then I am calling my overloaded method inside the same method.
currentState = myAgent.UserStateUpdate(prevAction, curState, e.Result);
UserStateUpdate method has 2 overloaded versions. First one gets Step1.State and second one gets Step2.State as differentiating parameter.. Like following;
IMDP.IState UserStateUpdate(IMDP.IAction act, Step1.State st, RecogResult rr)
IMDP.IState UserStateUpdate(Step2.Abuse.Action act, Step2.State st, RecogResult rr)
Application calls correct method for Step1.State but when application move to Step2 which uses Step2.State for state representation. It throws the following exception. Note, when i check what is stored in curState (typed dynamic) before calling the overloaded method, I am seeing a correct state which is typed Step2.State.
"The best overloaded method match for 'BI4A.Agent.Agent.UserStateUpdate(BI4A.IMDP.IAction, BI4A.Step1.State, System.Speech.Recognition.RecognitionResult)' has some invalid arguments"
Which basically states that the system tries to call overloaded method which accept Step1.State instead of Step2.State. I could not figure out, how to make it call the right method. Thanks for any help.