namespaces - 如何避免 haxe Type 类和 C# Type 类之间的冲突?

标签 namespaces haxe

我正在开发用 C# 转换并插入到 Unity 项目中的 Haxe 代码。

转换工作正常,当我在 Unity 中单独导入生成的类时,我能够使用它。 为了让它工作,我必须将整个生成的 src 文件夹引入 Unity,包括 Type.cs 文件。

但是,当我导入“后处理堆栈”(一个基本的 Unity 扩展)时,由于名称冲突而出现错误。 Type 类也是一个基本的 C# 类,它由后处理脚本使用。 haxe-Type优先并中断编译:

Assets/PostProcessing/Runtime/PostProcessingBehaviour.cs(406,30): error CS1502: The best overloaded method match for `System.Collections.Generic.Dictionary<Type,System.Collections.Generic.KeyValuePair<UnityEngine.Rendering.CameraEvent,UnityEngine.Rendering.CommandBuffer>>.Add(Type, System.Collections.Generic.KeyValuePair<UnityEngine.Rendering.CameraEvent,UnityEngine.Rendering.CommandBuffer>)' has some invalid arguments

Assets/PostProcessing/Runtime/PostProcessingBehaviour.cs(406,34): error CS1503: Argument `#1' cannot convert `System.Type' expression to type `Type'

我不知道是否可以通过尝试使用 C#/Unity/Mono 搜索路径来解决这个问题。

我想知道将所有 haxe 顶级类(可选)包装到 haxe 命名空间或特殊的 haxe-default 命名空间是否更合适,或者例如,将它们作为前缀添加到 class HType 中。 这种基本类型的名称冲突可能会出现在许多其他上下文中,而不仅仅是在 Unity 中。

最佳答案

我在 C# 的 Haxe 文档中找到了解决方案: https://github.com/HaxeFoundation/HaxeManual/wiki/Haxe-C%23

-D no-root generate package-less haxe types in the haxe.root namespace to avoid conflicts with other types in the root namespace

这样,所有全局级别的类都将在命名空间 haxe.root 下生成。

关于namespaces - 如何避免 haxe Type 类和 C# Type 类之间的冲突?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45631475/

相关文章:

haxe - 在 HashLink 上使用套接字读取 HTTP 请求

compiler-construction - 写入 REPL : where to start?

xcode - 如何针对 namespace 冲突强制执行编译器警告或错误?

visual-studio-2010 - 是否可以从 NDepend 分析中排除整个命名空间?

python - 如何使调用者的命名空间可用于导入函数中的 IPython 魔法?

python - 删除变量中的变量

ruby - 低效的 Ruby 方法命名 : passing namespace as argument as a way to call methods

performance - 在 Haxe 中循环的最有效方法是什么?

haxe - 如何使用 Haxe "package"声明?

generics - 是否可以对类字段和属性使用 Haxe 类型约束?