参数 1:无法从“Callbacks.OnConsoleLogHandler”转换到“Kotlin.Jvm.Functions.IFunction2”
我通过 .arr
文件创建了一个绑定库。
在其中一种方法中,我需要传递回调。
我想要做什么:
这是我的委托:
public class Callbacks
{
public delegate void OnConsoleLogHandler(string message, Sometype type);
}
这是我的 Configuration
类:
public class Configuration
{
public Callbacks.OnConsoleLogHandler onConsoleLog;
public Configuration()
{
}
public Configuration(Action<Configuration> action)
{
var config = new Configuration();
action?.Invoke(config);
onConsoleLog = config.onConsoleLog;
}
}
这是我尝试调用本机方法的方式:
public static void Start(Configuration configuration)
{
var onConsoleLog = configuration.onConsoleLog;
Package.Name.Configuration config = new Package.Name.Configuration();
config.SetOnConsoleLog(onConsoleLog);
}
但是在这一行 config.SetOnConsoleLog(onConsoleLog) ;
我收到错误:
Argument 1: cannot convert from 'Callbacks.OnConsoleLogHandler' to 'Kotlin.Jvm.Functions.IFunction2'
如果我尝试这样的操作:
config.SetOnConsoleLog(() => { });
我得到:
Cannot convert lambda expression to type 'IFunction2' because it is not a delegate type
如何将委托作为回调?有什么建议吗?
I created a binding library, via a .arr
file.
And in one of the methods I need to pass a callback.
What I was trying to do:
this is my delegate:
public class Callbacks
{
public delegate void OnConsoleLogHandler(string message, Sometype type);
}
this is my Configuration
class:
public class Configuration
{
public Callbacks.OnConsoleLogHandler onConsoleLog;
public Configuration()
{
}
public Configuration(Action<Configuration> action)
{
var config = new Configuration();
action?.Invoke(config);
onConsoleLog = config.onConsoleLog;
}
}
here's how I'm trying to call a native method:
public static void Start(Configuration configuration)
{
var onConsoleLog = configuration.onConsoleLog;
Package.Name.Configuration config = new Package.Name.Configuration();
config.SetOnConsoleLog(onConsoleLog);
}
But on this row config.SetOnConsoleLog(onConsoleLog);
I get error:
Argument 1: cannot convert from 'Callbacks.OnConsoleLogHandler' to 'Kotlin.Jvm.Functions.IFunction2'
If I try something like this:
config.SetOnConsoleLog(() => { });
I get:
Cannot convert lambda expression to type 'IFunction2' because it is not a delegate type
How can I put the delegate as a callback? Any suggestions?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论