如何知道Windows Mobile是否支持此方法?

时间:2012-11-06 12:33:48

标签: c# windows-mobile windows-mobile-6

有一些类(.NET framework 3.5)包含.NET Compact Framework支持的一些方法,以及一些不受支持的方法。还有一些.NET Compact Framework不存在的类。

例如对于System.IO.File类,.NET Compact Framework支持File.Create函数,但File.Encrypt函数不支持。{/ p>

另一个例子:.NET Compact Framework支持System.IO.File类,但System.Diagnostic.StackTrace不支持。{/ p>

我需要告诉编译器这样的东西:

#ifdef COMPACT_FRAMEWORK   // I'm compiling this from a smart device project

MyEncryptMethod("filename");

#else // I'm compiling this from a desktop project

File.Encrypt("filename");

#endif

我该怎么办?
(具体版本是Windows Mobile 6.1 Professional)。

3 个答案:

答案 0 :(得分:3)

要添加,因为您要显示 windows-mobile windows-mobile-6 ,您应该将#define约束更改为{{1}而不是PocketPC

COMPACT_FRAMEWORK

<强>更新

尼克:你说的是什么。 :)使用其中一个智能设备项目构建项目时,Visual Studio会自动将条件编译符号#ifdef PocketPC // PocketPC is what the WM SDK uses MyEncryptMethod("filename"); #else // I'm compiling this from a desktop project File.Encrypt("filename"); #endif 添加到项目中。

在VS2008的主菜单中,单击项目,然后在底部选择项目的属性。

在项目的“属性”页面上,转到“构建”选项卡,在那里您将看到已为您定义PocketPC的位置。

答案 1 :(得分:2)

您提供的代码很好,您只需要定义COMPACT_FRAMEWORK编译符号。

首先,定义在为紧凑框架构建程序集时将使用的构建配置。然后,在此构建配置中,只需定义COMPACT_FRAMEWORK条件编译符号。

条件编译符号在项目属性的Build选项卡中定义。

答案 2 :(得分:0)

以下是在类中查找Method的一些代码:

    public static bool execCmd(string sFunc, string sArg, ref string sResponse)
    {
        bool bRet = true;
        try
        {
            // Instantiate this class
            myCommands cmbn = new myCommands(sFunc, sArg);

            // Get the desired method by name: DisplayName
            //MethodInfo methodInfo = typeof(CallMethodByName).GetMethod("DisplayName");
            MethodInfo methodInfo = typeof(myCommands).GetMethod(sFunc);

            // Use the instance to call the method without arguments
            methodInfo.Invoke(cmbn, null);
            sResponse = cmbn.response;
        }
        catch (Exception ex)
        {
            System.Diagnostics.Debug.WriteLine("Exception in execCmd for '" + sFunc + "' and '" + sArg + "' " + ex.Message); 
            bRet = false; 
        }
        return bRet;
    }

您必须将myCommands更改为您正在搜索的类,并且必须将sFunc设置为您要查找的方法。使用该代码,您可以检查类中是否存在方法。

〜约瑟夫