c#在unity中的java库上的自省

本文关键字:自省 java unity 中的 | 更新日期: 2023-09-27 18:17:25

我使用IKVM将java库转换为。dll以在我的unity应用程序中使用。

如何用c#写这行java代码:

ProjectController pc = Lookup.getDefault().lookup(ProjectController.class);

org.gephi.project.api.ProjectController pc = org.openide.util.Lookup.getDefault().lookup(org.gephi.project.api.ProjectController.class);

自省似乎不起作用。似乎有一个问题,当我提到ProjectController.class

c#在unity中的java库上的自省

在。net运行时,相当于Java类的是System。类型的对象。有两种方法可以获得一个:在任何对象实例上调用GetType()(来自System。对象,所以一切都支持它)或使用typeof操作符。

可能也只能使用原始类名,但我希望它需要Type对象。这将取决于IKVM如何实现Java反射;我真的不知道。

当然,你也可以使用。net反射来完成所有的事情。我不知道如果这相当于你的例子行做什么,因为你正在使用一些奇怪的非标准的java反射样的东西,但它看起来像你只是试图得到一个类的"默认"实例…?

// I haven't tested this, but it may work:
ProjectController pc = Lookup.getDefault().lookup(typeof(ProjectController));
// You could also just try it without the ".class" part (since "class" is reserved in C#):
ProjectController pc = Lookup.getDefault().lookup(ProjectController);
// Or, if you want the .NET reflection "proper" way to do what I *think* you're attempting:
ProjectController pc = typeof(ProjectController).GetContructor(Type.EmptyTypes).Invoke(null);
// Of course, that's just the same thing as this simple line, so I probably misunderstood:
ProjectController pc = new ProjectController();