C#-APP:在运行时获取类型 [英] C#-APP:Getting type at runtime

查看:91
本文介绍了C#-APP:在运行时获取类型的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,有人可以帮我解决这个问题。

我想在运行时获取该属性的类型,但是当我在C#下面使用

代码时只返回类型为RuntimePropertyInfo

Hi all, can someone please help me on this.
I want to get the type of the property at run time but when I use the
code below C# just return the type as "RuntimePropertyInfo"

展开 | 选择 | Wrap | 行号

推荐答案

GetType()始终返回调用它的对象的类型,在本例中是PropertyInfo。您需要使用PropertyType属性。以下代码示例将执行您所需的操作:

GetType() always returns the type of the object it is called on, which in this case is PropertyInfo. You''ll need to use the PropertyType property instead. The following code sample will do what you need:

展开 | 选择 | Wrap | 行号


非常感谢。


之后我会跟进。

i想要获得该类型中的属性。


下面是我的类的示例,我想循环其中的所有属性

包括里面的类属性。
thanks so much.

I have a follow up though after that.
i want to get the Properties inside that Type.

Below is the sample of my class and i want to loop on all the properties inside it
including the class properties inside.
展开 | 选择 | Wrap | 行号


然后你可能需要设置一个递归函数:

Then you would probably need to set up a recursive function along the lines of:

展开 | 选择 | Wrap | 行号


这篇关于C#-APP:在运行时获取类型的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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