我目前正在尝试使用 overwolf 插件通过 TypeScript 调用 C# dll。
我想加载一个dll并调用一个函数,但是出现了未定义的错误。
我提到了此页面。
我已经将下面的 C# 类库构建为 dll。这个文件名是
ClassLibrary1.dll
.
namespace MyNameSpace {
public class MyClass {
public static bool isActive() {
// some code......
}
}
}
我在与 Typescript 项目的
plugins
相同的目录中创建了一个 manifest.json
文件夹,并将 ClassLibrary1.dll
放在那里。
并将以下内容添加到manifest.json
。
"data": {
"extra-objects": {
"myPlugin": {
"file": "plugins/ClassLibrary1.dll",
"class": "MyNamespace.MyClass"
}
},
}
↑(这种定义“类”的方式正确吗?)
最后,按下按钮时会调用该函数。
// on button pressed
button.addEventListener('click', () => {
overwolf.extensions.current.getExtraObject("myPlugin", (result) => {
// `result.success` is always true
try{
if (result.success) {
result.object.isActive(); // undefined
}else{
// never called here
}
}catch(e){
}
});
});
我做错了什么吗? 我曾经写过 C#,但我对 Typescript 和 Overwolf 很陌生。 谢谢你。
从 C# 代码中删除
static
解决了该问题。
结果:
namespace MyNameSpace {
public class MyClass {
public bool isActive() {
// some code......
}
}
}