簡體   English   中英

PCL Reflection使用BindingFlags獲取屬性

[英]PCL Reflection get properties with BindingFlags

我有下面的代碼。

    public static IEnumerable<PropertyInfo> GetAllPublicInstanceDeclaredOnlyProperties(this Type type)
    {
        var result =
            from PropertyInfo pi in type.GetProperties(BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly)
            select pi;

        return result;
    }

我正在嘗試將其轉換為PCL庫,但無法弄清楚。 我試過了

type.GetTypeInfo().DeclaredProperties.Where(x => x.BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly)

但是BindingFlags不存在。

我想念什么?

根據MSDN ,支持GetProperties方法:

支持於:可移植類庫

確保已包含System.Reflection命名空間。

GetProperties()System.Reflection.TypeExtensions類(一堆反射擴展方法)的一部分,因此包括名稱空間,您應該具有此擴展名和類似的擴展名。

如果仍然不可用,請嘗試通過NuGet包含System.Reflection.TypeExtensions程序集。

PM> Install-Package System.Reflection.TypeExtensions

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM