Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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. 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.

I have System.Reflection in my usings and if I create an Android library, I have GetConstructor/s available to me. The MSDN documentation definitely says it's in the PCL. Maybe this is me not totally understanding what PCL means in the Xamarin ecosystem, but I thought that meant it would be supported.

So, my question is, am I missing something or is this actually correct?

UPDATE

For anybody wanting to see how I did this;

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

like image 760
tbddeveloper Avatar asked Jul 05 '14 11:07

tbddeveloper


People also ask

What is difference between PCL and shared project in xamarin?

Shared Projects work well for application developers planning to use lots of platform-specific functionality in their cross-platform apps. While PCL projects continue to be supported in Visual Studio, . NET Standard is recommended for new projects.


Video Answer


1 Answers

Xamarin uses the same PCL profiles that Microsoft has released, but not all PCL profiles support 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):

var info = type.GetTypeInfo ();
foreach (var ctor in info.DeclaredConstructors) {
    // find the .ctor you want...
}
like image 118
jstedfast Avatar answered Oct 11 '22 12:10

jstedfast