I am trying to generate Xamarin bindings for a proprietary Android library (in other words, unfortunately I cannot share this library here). However I run into a problem with polymorphism. Here is the situation.
The library exposes 3 interfaces Location
, MobilityProfile
and Trip
all extend the interface Reading
.
The library also has an interface Measurement
which contains Reading getReading();
method which should always return one of the 3 mentioned interfaces (Location
, MobilityProfile
or Trip
).
I generated the bindings and compiled the binding project which works well. The next step would be to use the Xamarin.Android binding in my Xamarin project like this:
public void ProcessReading(IReading reading)
{
if (reading == null)
return null;
switch (reading)
{
case ILocation location:
// Process location
break;
case IMobilityProfile mobilityProfile:
// Process mobility profile
break;
case ITrip trip:
// Process trip
break;
default:
throw new NotSupportedException($"Processing the type '{reading.GetType().FullName}' is not supported.");
}
}
Now here I end up in the default
condition because the reading
parameter is of type IReadingInvoker
. Can anybody advise how I can solve this issue?