我认为你应该对此采取另一种策略。所有这些 gen-class 的东西只存在于 clojure 中,作为一种 hack,告诉编译器如何围绕本机 clojure 反射动态变量生成包装 Java/C# 类。
我认为最好在 C# 中完成所有“类”的工作,并让您的 clojure 代码更加原生。你的选择。但是如果你想这样,写一个这样的包装器:
using System;
using clojure.lang;
namespace ConsoleApplication {
static class Hello {
public static int Output(int a, int b) {
RT.load("hello");
var output = RT.var("code.clojure.example.hello", "output");
return Convert.ToInt32(output.invoke(a, b));
}
}
}
这样你的 C# 就可以看起来像普通的 C#
using System;
namespace ConsoleApplication {
class Program {
static void Main() {
Console.WriteLine("3+12=" + Hello.Output(3, 12));
Console.ReadLine();
}
}
}
clojure 可以看起来像普通的 clojure:
(ns code.clojure.example.hello)
(defn output [a b]
(+ a b))
无论您是编译它还是将其保留为脚本,这都将起作用。(RT.load("hello") 将加载脚本 hello.clj 如果它存在,否则它将加载 hello.clj.dll 程序集)。
This allows your clojure to look like clojure and your C# to look like C#. Plus it eliminates the static method clojure interop compiler bug (and any other interop bugs that may exist), since you're completely circumventing the clojure interop compiler.