简体   繁体   English

Xamarin PCL库中的GetConstructors

[英]GetConstructors in Xamarin PCL library

I am working on an android project with Xamarin and along the way, just as an exercise I decided to write my own simple IoC container. 我正在与Xamarin一起开发一个Android项目,并且在此过程中,我决定编写自己的简单IoC容器。 Now, I come to deciding if I need to inject any dependencies for my injected instances. 现在,我来决定是否需要为注入的实例注入任何依赖项。 I look up Type.GetConstructors, it says it's available in PCL projects, but I can not seem to get GetConstructors. 我查看了Type.GetConstructors,它说它可以在PCL项目中使用,但我似乎无法获得GetConstructors。

I have System.Reflection in my usings and if I create an Android library, I have GetConstructor/s available to me. 我在使用中有System.Reflection,如果我创建了一个Android库,我可以使用GetConstructor / s。 The MSDN documentation definitely says it's in the PCL. MSDN 文档肯定说它在PCL中。 Maybe this is me not totally understanding what PCL means in the Xamarin ecosystem, but I thought that meant it would be supported. 也许这不是我完全理解PCL在Xamarin生态系统中意味着什么,但我认为这意味着它会受到支持。

So, my question is, am I missing something or is this actually correct? 所以,我的问题是,我错过了什么或者这是否正确?

UPDATE UPDATE

For anybody wanting to see how I did this; 对于任何想看我怎么做的人;

https://github.com/tbd-develop/simpletypeprovider https://github.com/tbd-develop/simpletypeprovider

Xamarin uses the same PCL profiles that Microsoft has released, but not all PCL profiles support System.Type.GetConstructors(). Xamarin使用与Microsoft发布的相同的PCL配置文件,但并非所有PCL配置文件都支持System.Type.GetConstructors()。

You'll probably need to do something like this (hard to say for sure, because every PCL profile has different System.Reflection limitations): 你可能需要做这样的事情(很难肯定,因为每个PCL配置文件都有不同的System.Reflection限制):

var info = type.GetTypeInfo ();
foreach (var ctor in info.DeclaredConstructors) {
    // find the .ctor you want...
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM