本文介绍了MonoGame和& amp;之间的模棱两可的引用Microsoft.XNA.Framework命名空间的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

MonoGame(基本上将XNA引入Windows Phone 8的框架)的所有名称空间都以Microsoft.Xna.Framework为前缀,我相信可以将XNA应用程序移植到MonoGame时最大程度地减少代码更改量.

MonoGame (a framework which basically brings XNA to Windows Phone 8) has all it's namespaces prefixed with Microsoft.Xna.Framework I believe to minimise the amount of code changes required when porting your XNA app to MonoGame.

我的问题是,我希望访问Microphone类,由于尚未在MonoGame中创建该类,因此我必须在官方的Microsoft XNA类中使用它,这需要删除显式的强制删除项.我的MonoGame模板已设置以避免冲突的.csproj中的标准Microsoft.XNA.Framework.dll引用,它很好用,并且现在可以访问Microphone,但是这样做时,我在Microsoft中存在的几个关键类之间造成了歧义标准版和MonoGame.

My issue is, I wish to access the Microphone class, which, because has not been created in MonoGame yet, I have to utilize it from within in the official Microsoft XNA class, this requires taking out the explicit forced removal of the standard Microsoft.XNA.Framework.dll references within the .csproj that my MonoGame template has setup to avoid conflicts, which works great and now Microphone is accessible, but in doing so I have created ambiguity between a few key classes which both exist in Microsoft standard issue and MonoGame.

我收到的错误是:

这显然是发生的,因为与标准的Microsoft发行的XNA库一起,我引用了MonoGame.Framework.dll,它引用了命名空间,从而造成了这种歧义.但是,在所有情况下,我都希望访问MonoGame版本.

This has obviously occurred because alongside the standard Microsoft-issued XNA library, I have a reference to MonoGame.Framework.dll which commandeers the namespace, creating this ambiguity. However, in all instances, I wish to access the MonoGame version.

有什么想法可以明确地告诉编译器使用ColorVector2类的MonoGame版本,而不是正式的Microsoft版本?

Any ideas how I can explicitly tell the compiler to use the MonoGame version of the Color and Vector2 class and not the official Microsoft one?

using Color = Microsoft.Xna.Framework中的任何尝试显然都行不通,因为它们在已编译的dll中都被标记为相同!

Any attempt in a using Color = Microsoft.Xna.Framework obviously won't work because they are both labelled the same in the compiled dlls!

推荐答案

解决此特定问题的方法是使用extern alias( MSDN 教程).

The way to solve this specific problem is by using an extern alias (MSDN, tutorial).

这样,您可以为Microsoft XNA DLL加上别名,并仅为Microphone类指定适当的using语句.继续正常使用MonoGame.

That way you can alias the Microsoft XNA DLL and specify an appropriate using statement just for the Microphone class. Continue using MonoGame as normal.

可能更好的解决方案是使用此技术在名称空间Microsoft.Xna.Framework.Audio中创建自己的包装类Microphone.将其放在单独的程序集中,这样您就不必使用extern alias东西污染您的主要源代码.

Possibly a better solution might be to make your own wrapper class called Microphone in the namespace Microsoft.Xna.Framework.Audio using this technique. Put it in a separate assembly so you don't have to pollute your main source code with the extern alias stuff.

当然,理想的方法是为MonoGame实际实现Microphone并提供它;)

The ideal way, of course, is to actually implement Microphone for MonoGame and contribute it ;)

(当然,这个答案并没有说明您在功能上明智地以这种方式混合MonoGame和XNA可能会多么成功.希望它能起作用.)

(Of course, this answer says nothing about how successful you might be at mixing MonoGame and XNA in this way, functionality-wise. Hopefully it works.)

这篇关于MonoGame和& amp;之间的模棱两可的引用Microsoft.XNA.Framework命名空间的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-21 13:20