private void doWebLogin(String verifyCode, final ProcActionFuture future) {
LoginModule login = getContext().getModule(QQModule.Type.LOGIN);
QQAccount account = getContext().getAccount();
login.webLogin(account.getUsername(), account.getPassword(),
account.getUin(), verifyCode, new QQActionListener() { // 此处的QQActionListener是个接口,在下面
public void onActionEvent(QQActionEvent event) {
if (event.getType() == QQActionEvent.Type.EVT_OK) {
doCheckLoginSig( (String) event.getTarget(),future);
} else if (event.getType() == QQActionEvent.Type.EVT_ERROR) {
QQException ex = (QQException) (event.getTarget());
if(ex.getError()==QQErrorCode.WRONG_CAPTCHA){
doGetVerify(ex.getMessage(), future);
}else{
future.notifyActionEvent(
QQActionEvent.Type.EVT_ERROR,
(QQException) event.getTarget());
}
}
}
});
}
public interface QQActionListener {
public void onActionEvent(QQActionEvent event);
}
那么这种语法在C#里怎么【更好的】移植呢?
我现在的做法是重写一个类,继承QQActionListener,然后在实例化。
但是这种写法在这个项目中比较多,所以要为了一个方法就要重新写一个类,实在是太难看了。
请问有什么方法能更好的该写如上面的那样的java语法到C#吗
可以使用委托来模拟实现,单方法的接口直接用委托(Lambda表达式)解决,当然这个需要上层接口允许使用委托才行。多方法的接口需要实现一个辅助类