【问题标题】:Portable Class Library Profile 78 missing attribute related methods/properties可移植类库配置文件 78 缺少属性相关的方法/属性
【发布时间】:2013-11-13 12:45:26
【问题描述】:

在我的 PCL 核心项目(WP8、Android、iOS、Xamarin、MvvmCross)中,我使用自定义属性。 Type.GetCustomAttributes() 扩展方法让我检查使用的属性。

使用 PCL Profile104 效果很好。但是因为我想使用 async/await,所以我需要使用 PCL Profile78(和 .NET 4.5)

问题:似乎 GetCustomAttributes() 和 Attributes 属性在 Profile78 中不可用。为什么??

注意: 我正在通过创建 PCL Profile 104 类库并包装 GetCustomAttributes() 然后从我的 PCL Profile78 库中引用该库来研究解决方法。但是似乎不支持扩展方法...

示例代码:

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

【问题讨论】:

  • 这也发生在 Profile7 中

标签: c# xamarin.ios xamarin.android xamarin portable-class-library


【解决方案1】:

问题:似乎 GetCustomAttributes() 和 Attributes 属性在 Profile78 中不可用。为什么??

Profile78 includes support for Windows Store 8(如我的博客所述)和Windows Store has a more efficient implementation of Type-based reflection。本质上,您只需调用Type.GetTypeInfo 即可获得TypeInfo,从那里开始应该非常简单。

【讨论】:

  • 嘿,我切换到 System.Reflection.GetTypeInfo - 但它总是返回 null。我正在尝试 Profile49。有什么建议吗?
  • @skimania:这是一个与这个不同的问题,所以你应该将它作为一个单独的问题发布。然后更多的人会看到它,你会得到更好的答案。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2017-01-28
  • 1970-01-01
  • 2015-05-27
  • 2017-02-14
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多