Reflection IEnumerable.GetProperties()

Reflection IEnumerable.GetProperties(),reflection,c#-2.0,getproperties,Reflection,C# 2.0,Getproperties,我有一个类Foo,它派生自接口IFoo和IEnumerable public class Foo:IFoo,IEnumerable { public decimal Count {...} ///etc... } 如何调用GetProperties(),它只返回IEnumerable的公共属性(不是IFoo或此类)?要获取IEnumerable的属性,您甚至不需要引用Foo: typeof(IEnumerable).GetProperties(); 一旦您拥有了属性并且准备好使用

我有一个类Foo,它派生自接口IFoo和IEnumerable

public class Foo:IFoo,IEnumerable
{
   public decimal Count {...}
   ///etc...
}

如何调用GetProperties(),它只返回IEnumerable的公共属性(不是IFoo或此类)?

要获取IEnumerable的属性,您甚至不需要引用
Foo

typeof(IEnumerable).GetProperties();

一旦您拥有了属性并且准备好使用
PropertyInfo
对象获取值,那么您就可以将
Foo
类的实例传递给它以从中获取值。

如果我这样做:PropertyInfo[]pi=typeof(IEnumerable).GetProperties();它返回0个元素。IEnumerable需要在表中存储记录,我需要从表中读取所有列和记录。@Dublicator-这是因为IEnumerable没有属性。它只包含一个获取枚举数的方法。