.net - Detect Universal App at Runtime in PCL -


is there way detect main application universal app (w10) portable class library?

thanks

out-of-the-box not think functionality asking available in pcl, here suggestion involving reflection might want try.

it adapted pcl profile (328) using, involving .net 4 , silverlight 5. getplatformname method needs adjusted if want example switch pcl profiles 111 , 259, since these profiles have rely on typeinfo rather type.

here proposed method , accompanying interface, can implemented in portable class library:

public static class runtimeenvironment {     public static string getplatformname()     {         var callingassembly = (assembly)typeof(assembly).getmethod("getcallingassembly").invoke(null, new object[0]);         var type = callingassembly.gettypes().single(t => typeof(iplatform).isassignablefrom(t));         var instance = (iplatform)activator.createinstance(type);         return instance.platformname;     } }  public interface iplatform {     string platformname { get; } } 

apart above code, need implement iplatform interface in each platform-specific application, example this:

public class universalplatform : iplatform {     public string platformname => "uwp"; } 

in short, getplatformname method instantiates single class implementing iplatform interface in calling (application) assembly, , returns platformname property.

the assembly.getcallingassembly method not publicly exposed in of pcl profiles, implemented , can therefore accessed via reflection.

the getplatformname method portable , can consumed within portable class library itself, allowing make platform conditional decisions within pcl code. proposal require minimal code efforts within each platform-specific application, since need implement iplatform, maybe acceptable price pay?


Comments

Popular posts from this blog

java - Run spring boot application error: Cannot instantiate interface org.springframework.context.ApplicationListener -

python - pip wont install .WHL files -

Excel VBA "Microsoft Windows Common Controls 6.0 (SP6)" Location Changes -