I have the following method which uses yield return.
public static IEnumerable<T> GetSourceData<T>(int parentId) where T :class
{
Type documentType = typeof(T);
var shouldThrow = documentType.Namespace.StartsWith("Data.Company.Documents") == false;
if (shouldThrow)
{
throw new InvalidOperationException(string.Format("message here"));
}
/// Some more code goes on here
}
I have stepped through this code in the debugger and shouldThrow is false, but the control still continues on to throw the exception. Is this some silly thing with methods that are generic AND they use yield return?