2015-12-02 35 views
2

我有一個Portable Classlibrary。我應該在NETPortable中引用哪一個,找不到GetMethods

」 .NETPortable,版本= V4.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" 
     } 
    } 

    } 
} 

和cspro中的關鍵屬性Ĵ文件

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

回答

2

我不知道很多關於特定的配置文件(並與該配置文件測試什麼是給我周圍的預定義的類型不是提供大量的錯誤),但我知道反射現在分成在TypeTypeInfo之間。

機會是你想using指令

using System.Reflection; 

然後使用:(使用DeclaredMethods property

typeof(T).GetTypeInfo().DeclaredMethods 

需要注意的是,只有返回宣佈在給定的類的方法,不是遺傳的,這可能不是你所需要的。

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

後者索賠由PCL的支持,但可能不 - 在我的經驗,在MSDN版本信息正變得越來越難以信任,與DNX品種增加更復雜。

+0

謝謝。 typeof(T).GetTypeInfo()。DeclaredMethods is work – chsword

+0

@chsword:好的 - 只要你只需要聲明的方法,當然!令人討厭的是,我無法自己複製它......當我無法找到預定義類型時,我不知道問題是什麼。例如, –

+0

? @Jon Skeet – chsword

0

下面的例子爲我工作:

using System.Reflection; 

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