Portable Class Library Profile 78 missing attribute related methods/properties

旧城冷巷雨未停 提交于 2019-12-09 17:38:58

问题


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


回答1:


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.



来源:https://stackoverflow.com/questions/19741631/portable-class-library-profile-78-missing-attribute-related-methods-properties

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!