.net编写的,运行在智能设备上的程序有时候也需要运行在pc上,但有些功能在net和netcf上的实现方式不同,或者是一些其他的原因,使得程序在运行时需要动态识别自己究竟是运行在net frameword上还是智能设备的netcf上。在一个项目中遇到了这个问题,本来想通过判断net的版本号来识别,但没有找到合适的方法。因此临时用了下面的这个方法,虽然不是很好,但却是很有效(原理就是运行一个netcf不支持的功能,然后是否发生异常来决定)
我想应该有更加正统的方法来判断这个问题,继续探索中...
namespace MiniCafe.Util
{
public class Framework
{
/// <summary>
/// determine if app is running on netcf
/// </summary>
public static bool IsNetCF
{
get
{
bool flag = false;
try
{
System.IO.Directory.GetCurrentDirectory();
}
catch
{
flag = true;
}
return flag;
}
}
}
}
{
public class Framework
{
/// <summary>
/// determine if app is running on netcf
/// </summary>
public static bool IsNetCF
{
get
{
bool flag = false;
try
{
System.IO.Directory.GetCurrentDirectory();
}
catch
{
flag = true;
}
return flag;
}
}
}
}
我想应该有更加正统的方法来判断这个问题,继续探索中...