gpt4 book ai didi

c# - 在 C# 中,我如何判断一个属性是否是静态的? (.Net CF 2.0)

转载 作者:IT王子 更新时间:2023-10-29 04:18:02 27 4
gpt4 key购买 nike

FieldInfo 有一个 IsStatic 成员,但 PropertyInfo 没有。我想我只是忽略了我需要的东西。

Type type = someObject.GetType();

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

最佳答案

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

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

关于c# - 在 C# 中,我如何判断一个属性是否是静态的? (.Net CF 2.0),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/392122/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com