简体   繁体   中英

PCL Reflection get properties with BindingFlags

I have the code below.

    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;
    }

I am trying to convert this to a PCL library but I can not figure it out. I have tried

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

But BindingFlags doesn't exist.

What am I missing?

According to MSDN , GetProperties method is supported:

Supported in: Portable Class Library

Make sure you've included System.Reflection namespace.

GetProperties() is part of the System.Reflection.TypeExtensions class (a bunch of reflection extension methods) so include the namespace and you should have this and similar extensions available.

If it's still not available, try include System.Reflection.TypeExtensions assembly via NuGet .

PM> Install-Package System.Reflection.TypeExtensions

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM