I have a method which returns an IEnumerable<>
which it builds up using the yield return
syntax:
namespace Validation
{
public class UserValidator
{
public IEnumerable<ValidationError> Validate(User user)
{
if (String.IsNullOrEmpty(user.Name))
{
yield return new ValidationError("Name", ValidationErrorType.Required);
}
[...]
yield break;
}
}
}
If I put a breakpoint in the method, I can step over each line, but if I try to use the Watch or Immediate windows to view the value of a variable I get this error:
Cannot access a non-static member of outer type 'Validation.UserValidator.Validate' via nested type 'Validation.UserValidator'
Does anyone know why this is and how I can get around it?