Chris Kooken
Chris Kooken

Reputation: 33940

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?

Upvotes: 6

Views: 1955

Answers (1)

Niels Filter
Niels Filter

Reputation: 4528

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

Upvotes: 2

Related Questions