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?
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试):
问题:
回答1:
It seems that myObj.GetType().GetProperties()
IS valid. I just had to bring in System.Reflection by using System.Reflection
.
回答2:
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