【发布时间】:2017-07-09 20:42:30
【问题描述】:
今天我正在寻找一些带有 ilspy 的项目,我不明白如何像这样使用 Actions,在一个类中调用此方法
public void Login(Action success, Action<bool> failure)
{
if (!FB.IsInitialized)
{
Debug.Log("[FB] Not yet initialized. Will init again!");
FB.Init(new InitDelegate(this.OnInitComplete), null, null);
return;
}
new LoginWithReadPermissions(this.READ_PERMISSIONS, delegate
{
ServiceLocator.GetDB().SetBool("facebookBound", true, false);
this.OnLoginCompleted(success, failure);
}, delegate
{
failure(false);
});
}
这是上面方法调用的另一个类
public class LoginWithReadPermissions
{
private readonly Action _failureCallback;
private readonly Action _successCallback;
public LoginWithReadPermissions(string[] scope, Action success, Action failure)
{
this._successCallback = success;
this._failureCallback = failure;
FB.LogInWithReadPermissions(scope, new FacebookDelegate<ILoginResult>(this.AuthCallback));
}
private void AuthCallback(ILoginResult result)
{
if (result.Error == null && FB.IsLoggedIn)
{
this._successCallback();
}
else
{
this._failureCallback();
}
}
}
有人可以解释一下那里发生了什么吗?我从未遇到过这种 Action 用法。感谢您的回复。
【问题讨论】:
-
你说的是
delegate的用法吗?
标签: c# callback delegates action ilspy