Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 904
Chris Kooken Avatar asked Aug 14 '15 02:08

Chris Kooken


1 Answers

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
like image 193
Niels Filter Avatar answered Nov 03 '22 22:11

Niels Filter