Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
如何检查函数的返回类型是否为IEnumerable<T>?换句话说,我不想 match List<T>,即使它实现了IEnumerable<T>. 或者换一种说法,我如何检测函数是否延迟执行?
IEnumerable<T>
List<T>
我假设您正在与MethodInfo?
MethodInfo
Type returnType = methodInfo.ReturnType; bool isEnumerable = returnType.IsGenericType && returnType.GetGenericTypeDefinition() == typeof(IEnumerable<>);
当然,仅仅因为它返回IEnumerable并不意味着它使用延迟执行(即yield return),并且没有真正的方法可以在不反编译代码的情况下检查它。
IEnumerable
yield return