Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What's the equivalent for getting the list of constructors in .NET Standard / Core?

I'm trying to upgrade my .NET 4 project to .NETStandard and Core, but unable to find the equivalent for this:-

        var ctors = typeof(T).GetConstructors();

GetConstructors is a part of reflection, so seems like the support is intentionally lacking or moving...

Thanks. Simon.

like image 726
Simon Jefferies Avatar asked Mar 26 '17 19:03

Simon Jefferies


2 Answers

In .NET standard /Core a lot of reflexion api are moved to a specific package (system.reflection). This package provide the extension method GetTypeInfo on Type class.

typeof(T).GetTypeInfo().DeclaredConstructors;
like image 93
Kalten Avatar answered Oct 13 '22 00:10

Kalten


It's easy - just add GetTypeInfo():

var ctors = typeof(T).GetTypeInfo().DeclaredConstructors();
like image 28
Serge Semenov Avatar answered Oct 13 '22 00:10

Serge Semenov