I have 2 buttons, that both are to show a new viewmodel, but with different data passed to the viewmodel. The data is passed is not completely different, so they both inherit from the same base. Unfortunately, it seems like the data passed to the Init() method of the viewmodel loses its runtime type information on the way? Using a debugger (or code), the passed data is only recognised as the base-class - NOT the derived class that was actually constructed and passed to the ShowViewModel<>() method.
Is what im trying to do not possible?
public class BasePasser
{
}
public class PasserA : BasePasser
{
}
public class PasserB : BasePasser
{
}
public class ViewModelOne : MvxViewModel
{
// ...
private void DoSwitchViewModelA()
{
var tobepassed = new PasserA {
// ...
};
ShowViewModel<ViewModelTwo>(tobepassed);
}
private void DoSwitchViewModelB()
{
var tobepassed = new PasserB {
// ...
};
ShowViewModel<ViewModelTwo>(tobepassed);
}
}
public class ViewModelTwo : MvxViewModel
{
// ...
public async Task Init(BasePasser passed)
{
if(passed is PasserA)
{
// ...
}
else if(passed is PasserB)
{
// ...
}
else
{
// Always called/hit
throw new InvalidOperationException("Unknown data passed");
}
}
}