gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-11-30 23:33:08 24 4
gpt4 key购买 nike

我有一个可移植类库。

".NETPortable,Version=v4.5,Profile=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文件中的key属性

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

最佳答案

我不太了解那个特定的配置文件(用那个配置文件测试任何东西都会给我关于预定义类型不可用的大量错误),但我确实知道反射现在分为TypeTypeInfo

您可能需要一个 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/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com