I'm passing Task to Class library, where It needs to be executed, but with parameter value which can be obtained only within library Itself. I don't know how else to explain, maybe this example is more clear:
1.) Task that needs to be run from library:
public async Task<bool> Login(string _password)
{
//...
}
2.) Passing this Task to Class library (with string.Empty, because parameter will get It's real value in Class library)
var _check = _myLibrary.ShowLogin(() => _myMethods.Login(string.Empty));
3.) Execute Task from Class Library, but with real parameter value.
public partial class LoginWindow : Window
{
public ShowLogin(Func<Task<bool>> _checkpassword)
{
CheckPassword = _checkpassword;
}
public Func<Task<bool>> CheckPassword{ get; set; }
public MessageBoxResult Result { get; set; }
private async void Btn_login_Click(object sender, RoutedEventArgs e)
{
var _check = await CheckPassword(Txt_password.Text); // ERROR HERE!
if (!_check)
{
Result = MessageBoxResult.Cancel;
}
else
{
Result = MessageBoxResult.OK;
}
Close();
}
}
Class library holds a collection of custom Windows that I'm showing in WPF. In this particular Window user has to enter password for Login. If password is correct, user can enter application, otherwise not. That is whole point.
How can I call passed Task with parameter from library?
EDIT: Error is "'Delegate Func<Task>' does not take 1 arguments".