How can I conditionally compile my C# for Mono vs. Microsoft .NET?

后端 未结 2 1448
借酒劲吻你
借酒劲吻你 2020-11-27 04:09

I need a conditional compilation switch that knows if I am compiling for the mono or MS .NET runtime. How can I do this?

2条回答
  •  暗喜
    暗喜 (楼主)
    2020-11-27 04:42

    It is clear that there are times when code on one platform will differ to code on another and you may wish to do this at run-time or maybe compile time. Some times it can't be done at run-time.

    For example:

    Mono is used as the basis of Xamarin's Ios, Android, and Mac tool kits. While these have a lot of common code they also have classes which only appear on a single platform. When developing with these tool kits you develop native packages which are not exchangeable between platforms.

    A simple case is file names and paths. These differ on each platform. I just might to have a little condition to load the strings differently on each platform. Some platforms have case specific file names some don't.

    It would be nice if there was a little bit of code which returned the current platform - be it UNIX, iOS, Mac, X86, X64, XBox etc....

提交回复
热议问题