我有一个可移植类库。
“.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/