如何获取属性信息. [英] How to Get Properties information.

查看:65
本文介绍了如何获取属性信息.的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

亲爱的大家,


我创建了一个假设为Employee的类.该课程包括3个

属性,例如ID,名称,薪水.通过使用该类,我创建了雇员列表.


像List< employee> list = new List< employee>();

从该列表中,我想获取className,属性计数,属性名称以及

请给我任何想法.我想以一种通用的热情来创造它.我的意思是

List< t> list = new List< t>(); T可以是任何类或对象.


在此先谢谢您.

Dear Everybody,


I have created one class assume Employee. that class consists of 3

properties like Id, Name, Salary. By using that class i created list of Employees.


Like List<employee> list = new List<employee>();

from that list i want to get className , properties count, Properties Name aswell

Please give me any ideas. I want to create that in a Generic passion. what i mean is

List<t> list = new List<t>(); T can be any class or object.


Thanks in advance.

推荐答案

您需要使用Reflection
You would need to use Reflection http://msdn.microsoft.com/en-us/library/ms173183(v=vs.80).aspx[^]

However, there are drawbacks to using Reflection. Depending on your requirements it may be better to use an interface to guarantee certain methods and properties are available on the objects. Trying to use generics and reflection to create a one size fits all application has been tried many times without success.


这篇关于如何获取属性信息.的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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