PCL Reflection gets 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 cannot figure it out. I tried

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

But BindingFlags does not exist.

What am I missing?

+5
source share
1 answer

According to MSDN , the GetProperties method is supported:

Supported in: Portable Class Library

Make sure you include the System.Reflection .

GetProperties() is part of the System.Reflection.TypeExtensions class (a bunch of reflection extension methods), so include a namespace and you must have access to these and similar extensions.

If it is still unavailable, try enabling System.Reflection.TypeExtensions with NuGet .

 PM> Install-Package System.Reflection.TypeExtensions 
+1
source

All Articles