在 .NET Core 中获取类的公共属性 [英] Getting the public properties of a class in .NET core

查看:48
本文介绍了在 .NET Core 中获取类的公共属性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我注意到 .NET 核心不允许 myObj.GetType().GetProperties() 因为不存在 GetProperties 方法.有没有其他方法可以通过反射获取类的属性?

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?

推荐答案

看来 myObj.GetType().GetProperties() 是有效的.我只需要通过 using System.Reflection 引入 System.Reflection.

It seems that myObj.GetType().GetProperties() IS valid. I just had to bring in System.Reflection by using System.Reflection.

这篇关于在 .NET Core 中获取类的公共属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆