我应该在NETPortable中引用哪些,找不到GetMethods

时间:2015-12-02 09:11:23

标签: c# .net asp.net-core .net-core

我有一个便携式类库。

”。NETPortable,版本= 4.5版,档案= Profile75"

代码

typeof(T).GetMethods()

错误

cannot resolve symbol 'GetMethods'

我的project.json

{
  "supports": {},
  "dependencies": {

  },
  "frameworks": {
    ".NETPortable,Version=v4.5,Profile=Profile75": { },
    "net541": { },
    "dotnet5.4": {
      "dependencies": {
        "Microsoft.CSharp": "4.0.1-beta-23516",
        "System.Collections": "4.0.11-beta-23516",
        "System.Linq": "4.0.1-beta-23516",
        "System.Runtime": "4.0.21-beta-23516",
        "System.Threading": "4.0.11-beta-23516",
        "System.Reflection": "4.1.0-beta-23516",
        "System.Collections.Concurrent": "4.0.11-beta-23516"
      }
    }

  }
}

和csproj文件中的key属性

  <ProjectTypeGuids>{786C830F-07A1-408B-BD7F-6EE04809D6DB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>    
<TargetFrameworkVersion>v4.5</TargetFrameworkVersion>
    <TargetFrameworkProfile>Profile75</TargetFrameworkProfile>
    <MinimumVisualStudioVersion>11.0</MinimumVisualStudioVersion>

2 个答案:

答案 0 :(得分:2)

我对这个特定的配置文件了解不多(并且使用该配置文件测试任何内容会给我带来围绕预定义类型无法获得的大量错误),但我知道现在反射在TypeTypeInfo之间分配。

您可能需要using指令

using System.Reflection;

然后使用:

typeof(T).GetTypeInfo().DeclaredMethods

(使用DeclaredMethods property。)请注意,这只返回给定类中的声明方法,而不是继承的方法,这可能不是您需要的。

typeof(T).GetTypeInfo().GetMethods()

后者声明得到PCL的支持,但可能不是 - 根据我的经验,MSDN中的版本信息变得越来越难以信任,DNX品种增加了更多的复杂性。 / p>

答案 1 :(得分:0)

以下示例适用于我:

using System.Reflection;

namespace mynamespace {
  class MyClass() {
     void test() {
       var tMethods = typeof(DSRObject).DeclaringType.GetRuntimeMethods();
     }
  }
}