I notice that .NET core doesn't allow myObj.GetType().GetProperties()
as no GetProperties
method exists. Is there another way to obtain the properties of a class through reflection?
Asked
Active
Viewed 1.2k times
11

Søren
- 6,517
- 6
- 43
- 47

user3791372
- 4,445
- 6
- 44
- 78
-
6`myObj.GetType().GetTypeInfo().GetProperties()` – Nkosi Nov 13 '16 at 22:02
-
1Have you tried with this pkg https://www.nuget.org/packages/System.Reflection.TypeExtensions/ ? – Fernando Gonzalez Sanchez Nov 13 '16 at 22:02
-
See also: http://stackoverflow.com/questions/36118978/using-reflection-in-net-core – Blorgbeard Nov 13 '16 at 22:03
-
Nkosi No GetTypeInfo method appears to exist in .NET core – user3791372 Nov 13 '16 at 22:04
-
1It does, it's just an extra package. That's the philosophy in .NET Core - that's why the project is named "Core". Reflection isn't part of the core, since it means horrible dependencies, which make .NET Native a lot less useful. – Luaan Nov 13 '16 at 22:05
-
Actually, it would appear I was missing a Using declaration for System.Reflection! Not using resharper at the moment! Thanks – user3791372 Nov 13 '16 at 22:11
-
@user3791372 post that as an answer and accept it. – Lex Li Nov 14 '16 at 01:53
2 Answers
20
It seems that myObj.GetType().GetProperties()
IS valid. I just had to bring in System.Reflection by using System.Reflection
.

user3791372
- 4,445
- 6
- 44
- 78
11
Just to sum up to anyone else, just adding using System.Reflection
to the top of the page is not enough. You will have to add the System.Reflection.TypeExtensions
NuGet package as described in the question comments.
PM> Install-Package System.Reflection.TypeExtensions -Version 4.3.0

Moslem Ben Dhaou
- 6,897
- 8
- 62
- 93
-
1/ This is a comment to a comment written as an answer, 2/ No you don't. 3./ This garnered an upvote surprisingly quickly. – user3791372 Jul 24 '17 at 10:54
-
1Yes you do. I had the same issue in a .NET Standard 1.6 project and only the combination above solved it for me. In .NET Core unfortunately namespaces are now spread over multiple assemblies. – Moslem Ben Dhaou Jul 24 '17 at 11:28
-
11/ Yeah you do 2/Seems like if you're answering your own question (and not a complete answer) you're on shaky ground about getting picky with upvotes... I upvoted both of you... Together it's a complete answer – Rikon Jul 28 '17 at 14:09
-
@MoslemBenDhaou the question refers to ".Net Core" not .Net Standard – user3791372 Sep 08 '17 at 18:05