11

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?

Søren
  • 6,517
  • 6
  • 43
  • 47
user3791372
  • 4,445
  • 6
  • 44
  • 78

2 Answers2

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
  • 1
    Yes 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
  • 1
    1/ 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