ConstructorInfo GetCustomAttributes不同的实现 [英] ConstructorInfo GetCustomAttributes different implementations
问题描述
在面向Windows 8.1和Windows Phone 8.1的类库中,我有以下代码,其中GetCustomAttributes返回IEnumerable< Attribute>。
< pre class ="prettyprint"> int amountOfParams = constr [x] .GetCustomAttributes(true).Count();
在我的通用应用程序中,我在Windows中导入了库,在Windows Phone项目中,如果我在这里打开类,我会看到同一行返回一个Object []。
所以我尝试用这样的预处理器指令修复它:
#if WINDOWS_PHONE_APP
int amountOfParams = constr [x] .GetCustomAttributes(true).Length;
#else
int amountOfParams = constr [x] .GetCustomAttributes(true).Count();
#endif
但是这不起作用它总是选择其他,我也注意到在VS2013更新4的下拉框中指定了如何查看代码只列出(杂项文件)。
有没有办法解决这个问题?
亲切的问候,
EpicParser
确保您的项目在Project-> Properties-> Build-> General下包含条件编辑符号NETFX_CORE和WINDOWS_APP。
有关更多信息,请参阅以下链接:
http://www.codeproject.com/Articles/ 845485 /条件编译通用应用程序
http://stackoverflow.com/questions/25975391/the-if -windows-app-directive-never-run-in-a-universal-windows-app-solution
还要记得将有用的帖子标记为关闭你的帖子的答案,然后如果你有新的问题就开始一个新的帖子。
In a class library that targets Windows 8.1 and Windows Phone 8.1 I have the following code, where the GetCustomAttributes returns IEnumerable<Attribute>.
int amountOfParams = constr[x].GetCustomAttributes(true).Count();
In my universal app I imported the library in the Windows and in the Windows Phone project if I open the class here I see that the same line returns an Object[].
So I tried to fix it with preprocessor directives like this:
#if WINDOWS_PHONE_APP int amountOfParams = constr[x].GetCustomAttributes(true).Length; #else int amountOfParams = constr[x].GetCustomAttributes(true).Count(); #endif
But this doesn't work it always chooses the else, I also noticed that in VS2013 update 4 the drop down box that specifies how to view the code only lists (Miscellaneous Files).
Is there a way to fix this problem?
With kind regards,
EpicParser
Make sure that your project contains the conditional compilations symbols NETFX_CORE and WINDOWS_APP under Project->Properties->Build->General.
Please refer to the following links for more information:
http://www.codeproject.com/Articles/845485/Conditional-Compilation-in-Universal-Apps
http://stackoverflow.com/questions/25975391/the-if-windows-app-directive-never-runs-in-a-universal-windows-app-solution
Please also remember to mark helpful posts as answer to close your thread and then start a new thread if you have a new question.
这篇关于ConstructorInfo GetCustomAttributes不同的实现的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!