便携式类库档案失踪78属性相关的方法/属性 [英] Portable Class Library Profile 78 missing attribute related methods/properties
问题描述
在我的PCL核心项目(WP8,Android版,iOS版,Xamarin,MvvmCross)我使用自定义属性。该Type.GetCustomAttributes()扩展方法可以让我检查一下所使用的属性。
使用PCL Profile104这个效果很好。但是,因为我想用异步/的await,我需要使用PCL Profile78(和.NET 4.5)
问题:看来GetCustomAttributes()和Attributes属性不在Profile78可用。为什么?
请注意:
我通过创建一个配置文件PCL 104类库和包装的GetCustomAttributes(),然后从引用这个库寻找到解决办法我PCL Profile78库。但是似乎extensionmethods不支持...
示例代码:
公共Pcl78Class()
{
型T = this.GetType();
VAR属性= t.Attributes;
VAR customAttributes = t.GetCustomAttributes(真);
//另一个奇怪的事情:为什么VS CodeCompletion告诉我它知道CustomAttributeExtensions类和方法?
//System.Reflection.CustomAttributeExtensions.GetCustomAttributes(t);
}
问题:似乎GetCustomAttributes()和Attributes属性都无法在Profile78。为什么?
块引用>
的 Profile78包括Windows应用商店8 支持(如我的博客上指出),和的 Windows应用商店拥有更高效的执行<$ C $的C>键入基于反射。从本质上讲,你只需要调用
Type.GetTypeInfo
获得所属类别
,并从那里应该是相当简单的。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); }
解决方案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 callType.GetTypeInfo
to get aTypeInfo
, and from there it should be pretty straightforward.这篇关于便携式类库档案失踪78属性相关的方法/属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!