我正在尝试使用这种方法: https : //developer.xamarin.com/api/member/System.Type.GetInterfaces()/喜欢这样:
public MainPage(Type type) { if (type.GetInterfaces().contains("Form")) { // go on但是我的Xamarin Studio不能识别GetInterfaces方法,为什么?
I'm trying to use this method: https://developer.xamarin.com/api/member/System.Type.GetInterfaces()/ like this:
public MainPage(Type type) { if (type.GetInterfaces().contains("Form")) { // go onBut my Xamarin Studio does not recognize the GetInterfaces method, why?
最满意答案
这听起来像你正在使用PCL Xamarin Forms项目。 我建议你在这里阅读更多关于这方面的内容,或者观看互联网上的一些有用的视频(例如这个讨论不同PCL配置文件的视频),但基本上PCL项目试图允许在所有平台上提供许多通用API。 这意味着如果某个平台不支持GetInterfaces()或者如果Forms团队尚未实现该API,则它将不会从Forms项目中获得。
Xamarin Forms的好处在于,如果需要,您仍然可以访问所有本机API。 为此,您可以创建一个接口并使用Xamarin Forms Dependency Service( 链接 ),这可能允许您从Forms项目访问该API。
如果你需要一个如何做到这一点的例子,请让我知道。
It sounds like you are using a PCL Xamarin Forms project. I suggest you read more about that here or watch some of the helpful videos around the internet (like this one, which talks about different PCL Profiles) but basically and PCL project attempts to allow many of the common APIs available on all platforms. This means that if a certain platform does not support GetInterfaces() or if the Forms team has not implemented that API yet, it will not be available to your from the Forms project.
The nice thing about Xamarin Forms is that you can still access all native APIs if you need to. To do this you would create an interface and use Xamarin Forms Dependency Service (link) which would probably allow you to access that API from your Forms project.
If you need an example of how to do that, just let me know.
更多推荐
发布评论