Giả sử mình có Method như thế này:
public static IEnumerator<int> SomeMethod(bool condition)
{
Console.WriteLine("1");
if (condition == true) // <==
yield return 1; // <==
Console.WriteLine("2");
yield break;
}
Bây giờ mình MUỐN chỗ yield return nó thành như thế này (vì mình muốn làm rất nhiều yield return kiểu như thế):
public static IEnumerator<int> SomeMethod(bool condition)
{
Console.WriteLine("1");
YieldReturn(condition); // <==
Console.WriteLine("2");
yield break;
}
Tức là mình gọi một method hoặc một cái gì đó, cái đó sẽ yield return hàm của mình nếu condition == true, nếu bằng false thì bỏ qua.
Liệu có cách nào đạt được không nhỉ?