Tôi có hai phương thức trong C# 3.5, giống hệt như một hàm gọi, trong đoạn dưới đây, hãy xem clientController.GetClientUsername vs clientController.GetClientGraphicalUsernameTrong C# 3.5, Làm thế nào để bạn vượt qua phương thức nào để gọi trên một đối tượng dưới dạng tham số
private static bool TryGetLogonUserIdByUsername(IGetClientUsername clientController, string sClientId, out int? logonUserId)
{
string username;
if (clientController.GetClientUsername(sClientId, out username))
{
// ... snip common code ...
}
return false;
}
private static bool TryGetLogonUserIdByGraphicalUsername(IGetClientUsername clientController, string sClientId, out int? logonUserId)
{
string username;
if (clientController.GetClientGraphicalUsername(sClientId, out username))
{
// ... snip common code ...
}
return false;
}
Có cách nào (đại biểu, lamda?) Mà tôi có thể chuyển sang phương thức nào trên clientController mà tôi muốn gọi?
Cảm ơn!
Mẫu là một ví dụ của một vấn đề chung mà tôi đã gặp phải khi tái cấu trúc các khối mã giống hệt nhau các lệnh gọi phương thức thanh. Đặc biệt, tôi dường như thấy chúng trong các bài kiểm tra. –