-1

I'm making app with using Xamarin.forms pcl.

I already know we use "Device.OS" to distinguish what platform is when we use pcl.

But in some cases, I need to use define header to archive it, but I can't find a solution.

I want to use different derived class for each platform in some case.

like this

#if __ANDROID__
    public class SkiaView_BG : SKCanvasView
#else
    public class SkiaView_BG : SKGLView
#endif
Bright Lee
  • 2,306
  • 2
  • 27
  • 55
  • Have you read through the documentation? I'm not sure what your question is: [Conditional Compilation](https://developer.xamarin.com/guides/cross-platform/application_fundamentals/building_cross_platform_applications/part_4_-_platform_divergence_abstraction_divergent_implementation/#Conditional_Compilation) – Jon Douglas Jan 25 '17 at 23:25
  • @JonDouglas Hi Jon again, DavidS answered my question. :) – Bright Lee Jan 26 '17 at 04:48
  • And I think example code above explain what I want to do. – Bright Lee Jan 26 '17 at 04:48
  • 1
    @BrightLee is there a reason why the Android view needs to be a canvas view, while iOS is a GL view? What is the issue with the Android? - the transparency? I think Android is a bit limited (http://stackoverflow.com/questions/2034822/android-opengl-es-transparent-background) in that you can either have an opaque GL surface below everything, or a transparent GL surface above everything. Nothing in between. https://github.com/mono/SkiaSharp/issues/223 – Matthew Jan 28 '17 at 22:00
  • Thanks for reply @Matthew . – Bright Lee Jan 29 '17 at 14:20

1 Answers1

2

No. The whole point of a PCL is that the code is compiled once, and the exact same DLL is used by both Android and iOS (or whatever platforms you target). Thus no #if for targeting different platforms.

If you really need to share most of the code between platforms, but with some platform-specific code like you have in your example above, you should look into shared projects.

If you need to use a PCL, then you need to find a way to turn this into a custom renderer, or other approach to move that class into each platform-specific project.

DavidS
  • 2,904
  • 1
  • 15
  • 21