{"id":200,"date":"2009-11-17T21:25:16","date_gmt":"2009-11-17T20:25:16","guid":{"rendered":"http:\/\/www.gennard.net\/blog\/?p=200"},"modified":"2009-11-17T21:25:16","modified_gmt":"2009-11-17T20:25:16","slug":"detecting-the-use-mono-clr-dynamically","status":"publish","type":"post","link":"http:\/\/www.gennard.net\/blog\/2009\/11\/detecting-the-use-mono-clr-dynamically\/","title":{"rendered":"Detecting the use Mono CLR dynamically"},"content":{"rendered":"<p>While developing something that could be used on Mono on Windows, Mono on Unix and on Windows with Microsoft&#8217;s CLR, I needed to be sensitive to the environment but didn&#8217;t want to conditionally compile my code different.   So I put together a quick class to help..   Below is the C# code with pics of it running on Windows\/Mac&#8230;<\/p>\n<p><code lang=\"csharp\" width=\"800\" lines=\"-1\" nowrap=\"0\"><br \/>\nusing System;<br \/>\nusing System.Reflection;<\/p>\n<p>namespace Gennard.Net<br \/>\n{<br \/>\n\tpublic class CLRUtils<br \/>\n\t{<br \/>\n\t\tprivate static readonly bool isMono= Type.GetType(\"Mono.Runtime\") == null ? false : true;<\/p>\n<p>\t\tprivate static readonly int eOSp = (int)Environment.OSVersion.Platform;<br \/>\n\t\tprivate static readonly bool isUnix =  (eOSp == 4) || (eOSp == 128);<\/p>\n<p>\t\t\/* Class Properties *\/<br \/>\n\t\tpublic static bool IsMono { get { return isMono; } }<br \/>\n\t\tpublic static bool IsUnix { get { return isUnix; } }<\/p>\n<p>\t\tpublic static void Main()<br \/>\n\t\t{<br \/>\n\t\t\tConsole.WriteLine(\"Are we using Mono? : \"+IsMono);<br \/>\n\t\t\tConsole.WriteLine(\"Are we using Unix? : \"+IsUnix);<br \/>\n\t\t}<br \/>\n\t}<br \/>\n}<br \/>\n<\/code><\/p>\n<p>The taste of the pudding mix.. is in the eating.. so lets see it working&#8230; <\/p>\n<p><img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/www.gennard.net\/blog\/wp-content\/uploads\/2009\/11\/Windows_Use.png\" alt=\"On Windows....\" title=\"On Windows....\" width=\"457\" height=\"149\" class=\"alignnone size-full wp-image-204\" \/><\/p>\n<p><img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/www.gennard.net\/blog\/wp-content\/uploads\/2009\/11\/Mac_Use.png\" alt=\"On the Mac, we get....\" title=\"On the Mac, we get....\" width=\"400\" height=\"111\" class=\"alignnone size-full wp-image-203\" \/><\/p>\n","protected":false},"excerpt":{"rendered":"<p>While developing something that could be used on Mono on Windows, Mono on Unix and on Windows with Microsoft&#8217;s CLR, I needed to be sensitive to the environment but didn&#8217;t want to conditionally compile my code different. So I put &hellip; <a href=\"http:\/\/www.gennard.net\/blog\/2009\/11\/detecting-the-use-mono-clr-dynamically\/\">Continue reading <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[4,7,20,32],"tags":[208,218,227],"_links":{"self":[{"href":"http:\/\/www.gennard.net\/blog\/wp-json\/wp\/v2\/posts\/200"}],"collection":[{"href":"http:\/\/www.gennard.net\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/www.gennard.net\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/www.gennard.net\/blog\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"http:\/\/www.gennard.net\/blog\/wp-json\/wp\/v2\/comments?post=200"}],"version-history":[{"count":0,"href":"http:\/\/www.gennard.net\/blog\/wp-json\/wp\/v2\/posts\/200\/revisions"}],"wp:attachment":[{"href":"http:\/\/www.gennard.net\/blog\/wp-json\/wp\/v2\/media?parent=200"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/www.gennard.net\/blog\/wp-json\/wp\/v2\/categories?post=200"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/www.gennard.net\/blog\/wp-json\/wp\/v2\/tags?post=200"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}