Saturday, January 5, 2013

How to determine .net platform at runtime from portable library?

How to determine .net platform at runtime from portable library?

Specifically I want to be able to determine at runtime when portable class library code is running on Silverlight, WinRT, or .NET

My best idea right now is:

typeof(object).Assembly.GetCustomAttribute<AssemblyProductAttribute>().Product 

On .NET it returns "Microsoft® .NET Framework" and on Silverlight it returns "Microsoft® Silverlight" but I'm not sure if it distinguishes itself on WinRT as I'm not developing with Windows 8 at the moment.

So I'd like to know if that works or any better ideas.

Answers & Comments...

Answer: 1

While there are usually very few good reasons for it, here's a class that does so:

http://mvvmlight.codeplex.com/SourceControl/network/forks/onovotny/MvvmLightPortable/changeset/view/f356af74426f#GalaSoft.MvvmLight/Portable/GalaSoft.MvvmLight/Helpers/DesignerPlatformLibrary.cs

I use it as part of logic to determine IsInDesignTime for a PCL.

by : Oren Novotnyhttp://stackoverflow.com/users/738188




No comments:

Post a Comment

Send us your comment related to the topic mentioned on the blog