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

夙愿已清 提交于 2019-11-26 18:44:54

The Mono compiler defines __MonoCS__

BUT, BUT, BUT, the whole point of Mono is that you can take an assembly that you built with VS and run it on Mono, or vice versa.

It seems to me that if you need to have Mono vs MS.NET differences, then you need to be making those decisions at run-time.

The standard way to detect Mono at Runtime is:

bool runningOnMono = Type.GetType ("Mono.Runtime") != null;

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....

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!