Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Portable Class Library Profile 78 missing attribute related methods/properties

In my PCL core project (WP8, Android, iOS, Xamarin, MvvmCross) I use custom attributes. The Type.GetCustomAttributes() extension method lets me examine the attributes used.

Using PCL Profile104 this works well. But because I want to use async/await, I'll need to use PCL Profile78 (and .NET 4.5)

Problem: Seems the GetCustomAttributes() and the Attributes property are not available in Profile78. Why??

Note: I am looking into the workaround by creating a PCL Profile 104 class library and wrapping the GetCustomAttributes() and then referencing this library from my PCL Profile78 library. However it seems extensionmethods are not supported...

Example Code:

public Pcl78Class()
{
    Type t = this.GetType();
    var attributes = t.Attributes;
    var customAttributes = t.GetCustomAttributes(true);

    // another weird thing: Why is VS CodeCompletion telling me it knows CustomAttributeExtensions class and methods?
    //System.Reflection.CustomAttributeExtensions.GetCustomAttributes(t);
}

enter image description here

like image 820
Arthur Kater Avatar asked Nov 02 '13 11:11

Arthur Kater


1 Answers

Problem: Seems the GetCustomAttributes() and the Attributes property are not available in Profile78. Why??

Profile78 includes support for Windows Store 8 (as noted on my blog), and Windows Store has a more efficient implementation of Type-based reflection. Essentially, you just have to call Type.GetTypeInfo to get a TypeInfo, and from there it should be pretty straightforward.

like image 174
Stephen Cleary Avatar answered Sep 28 '22 01:09

Stephen Cleary