How to implement platform specific input with PCL

Hello again,

so i’m really new to the PCL concept. I build a solution with 3 projects (like the xamarin tutorial):
PuzzleGame (pcl)

Now I’m facing the problem, how to implement platform specific input. My idea was to create an interface in the pcl project and to implement this interfaces in the platform specific projects.

But how should I use the implementation.

IInput input = new PuzzleGame.Windows.PlatformInput();

… doesn’t work. I’m using Xamarin Studio.

I don’t know which Xamarin tutorial you mean, but I assume that the platform-specific assemblies (PuzzleGame.Android, PuzzleGame.Windows) contain the Game class. When the Game is initialized you can call

IInput input = new PlatformInput();

in the platform-specific assembly. Then you can simply pass the interface to the PCL assembly. (You can pass IInput simply as a method argument. Or better: You can use store the interface in an IServiceProvider and pass the IServiceProvider to the PCL assembly. Google for “service locator pattern” or “inversion of control container” to find out more.)

Of course! How couldn’t I see this simple solution? Thank you for opening my eyes!

This is the Xamarin tutorial I was talking about:

Thank you again!