c# - 我应该在 NETPortable 中引用哪个,找不到 GetMethods

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

我有一个可移植类库。

“.NETPortable,版本=v4.5,配置文件=Profile75”

代码

typeof(T).GetMethods()

有错误

cannot resolve symbol 'GetMethods'

我的项目.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文件中的关键属性

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

最佳答案

我不太了解该特定配置文件(并且使用该配置文件测试任何内容都会给我带来关于预定义类型不可用的大量错误),但我确实知道反射现在分为类型TypeInfo

您可能需要一个 using 指令

using System.Reflection;

然后使用:

typeof(T).GetTypeInfo().DeclaredMethods

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

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

后者声称受到 PCL 支持,但可能并非如此 - 根据我的经验,MSDN 中的版本信息变得越来越难以信任,DNX 品种增加了更多复杂性。

关于c# - 我应该在 NETPortable 中引用哪个,找不到 GetMethods,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34038768/

相关文章:

c# - VS 2010 Beta 1 无法识别 System.Printing.PrintTicket 类

javascript - 数据来自API,但不显示。 Angular 9 ABP 框架

c# - 是否可以在派生类中添加 XmlIgnore 属性?

c# - 使用 chrome 驱动程序查找元素

c# - 使用 Microsoft Graph token 通过 Jwt Bearer token 保护 ASP.NET Core Web API

c# - 在 ASP.NET Core 中解密 ".AspNetCore.Session"cookie

asp.net-core - 在测试中使用 MediatR 时无法访问已处置的对象 (IServiceProvider)

时间:2019-05-17 标签:c#mysqlconnectionstring问题

c# - EF Core 5.0 中的多对多关系是否可以配置为仅保留一个导航属性(在一侧)?

c# - 有没有办法轻松屏蔽输入框对象