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?
GetProperties() Returns all the public properties of the current Type.
Properties can be marked as public , private , protected , internal , protected internal , or private protected . These access modifiers define how users of the class can access the property. The get and set accessors for the same property may have different access modifiers.
Reflection provides objects (of type Type) that describe assemblies, modules, and types. You can use reflection to dynamically create an instance of a type, bind the type to an existing object, or get the type from an existing object and invoke its methods or access its fields and properties.
It seems that myObj.GetType().GetProperties()
IS valid. I just had to bring in System.Reflection by using System.Reflection
.
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With