在C#中,我怎么能知道一个属性是静态的? (.NET CF 2.0) [英] In C#, how can I tell if a property is static? (.Net CF 2.0)

查看:93
本文介绍了在C#中,我怎么能知道一个属性是静态的? (.NET CF 2.0)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

字段信息具有IsStatic构件,但的PropertyInfo没有。我以为我只是俯瞰我需要什么。

 键入类型= someObject.GetType(); 

的foreach(PI的PropertyInfo在type.GetProperties())
{
//嗯...不知道如何判断这个属性是静态的
$} b $ b


解决方案

要确定一个属性是否是静态的,您必须获得MethodInfo的为get或set访问,通过调用GetGetMethod或GetSetMethod方法,并检查其IsStatic财产。



的http:// MSDN .microsoft.com / EN-US /库/ system.reflection.propertyinfo.aspx


FieldInfo has an IsStatic member, but PropertyInfo doesn't. I assume I'm just overlooking what I need.

Type type = someObject.GetType();

foreach (PropertyInfo pi in type.GetProperties())
{
   // umm... Not sure how to tell if this property is static
}

解决方案

To determine whether a property is static, you must obtain the MethodInfo for the get or set accessor, by calling the GetGetMethod or the GetSetMethod method, and examine its IsStatic property.

http://msdn.microsoft.com/en-us/library/system.reflection.propertyinfo.aspx

这篇关于在C#中,我怎么能知道一个属性是静态的? (.NET CF 2.0)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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