Search code examples
c#iosxamarin.iosopentk

Can I avoid Exporting LayerClass in Views derived from iPhoneOSGameView?


Given a class:

public class BaseGameView : OpenTK.Platform.iPhoneOS.iPhoneOSGameView {

Constructing BaseGameView at runtime will throw System.Exception: Failed to find selector layerClass... This is easily resolved by adding the following to the class definition:

    [Export ("layerClass")]
    public static new Class GetLayerClass()
    {
        return iPhoneOSGameView.GetLayerClass();
    }

This is not so undesirable until I derive another class as follows:

public class DerivedGameView : BaseGameView {

Constructing the DerivedGameView also throws the same exception unless I Export("layerClass") from that class as well.

How can I DRY this out? I have a handful of these derived views and they all have to have the same snippet of code exporting the layer class... I'd rather not repeat it.

A related question is:
Why is this not necessary for a class simply derived from UIView?

Cheers!


Solution

  • This is currently a limitation inside MonoTouch - static methods from base classes aren't exported.

    I have filed a bug report for this: https://bugzilla.xamarin.com/show_bug.cgi?id=6170 - you can CC yourself on this bug to get notified when it's fixed.