Skip to content

Instantly share code, notes, and snippets.

@andylind
Created February 12, 2013 01:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save andylind/4759407 to your computer and use it in GitHub Desktop.
Save andylind/4759407 to your computer and use it in GitHub Desktop.
This C# class can be used to return both a result and a validation value. In some cases it may also make sense to include an optional validation error message in the class.
// Used when both a result and a validation value are needed
public class ValidatedResponse<T>
{
private readonly bool isOk;
public T Item { get; private set; }
public ValidatedResponse(bool isOk, T item)
{
this.isOk = isOk;
Item = item;
}
public bool IsNotValid()
{
return !this.isOk;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment