C# 反射-获取作为接口的类的属性

C# 反射-获取作为接口的类的属性,c#,reflection,C#,Reflection,我使用refelection遍历类的公共属性 foreach (PropertyInfo prop in instance.GetType().GetProperties()) { ...do work 这让我得到了所有的公共财产。但是,我只想获得作为接口的公共属性。例如,下面我想得到“会话”(这是一个接口),但没有帮助 public ISession Session { get; set; } //My Interface - i want this public string He

我使用refelection遍历类的公共属性

foreach (PropertyInfo prop in instance.GetType().GetProperties())
{
  ...do work 
这让我得到了所有的公共财产。但是,我只想获得作为接口的公共属性。例如,下面我想得到“会话”(这是一个接口),但没有帮助

public ISession Session { get; set; } //My Interface - i want this

public string Help { get; set; } //I dont want this
用于确定属性的类型是否为接口类型

Type t = typeof ( YourType );

foreach ( PropertyInfo p in t.GetProperties () )
{
    if ( p.PropertyType.IsInterface )
    {
        // p is an interface property
    }
}