jbtule
jbtule

Reputation: 31799

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.

Upvotes: 2

Views: 1276

Answers (1)

Claire Novotny
Claire Novotny

Reputation: 1701

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.

Upvotes: 2

Related Questions