Skip to content

Instantly share code, notes, and snippets.

@robfe
Created July 23, 2013 04:17
Show Gist options
  • Save robfe/6059822 to your computer and use it in GitHub Desktop.
Save robfe/6059822 to your computer and use it in GitHub Desktop.
string to boolean transforms for specflow step names
[Binding]
public class StepArgumentTransforms
{
static readonly List<string> _positives = "is,can,will,should,does,do,have,correct".Split(',').ToList();
static readonly List<string> _negatives = "{0}n't,{0}not,{0} not,{0} no,in{0},un{0}".Split(',').SelectMany(s => _positives.Select(word => string.Format(s, word))).ToList();
[StepArgumentTransformation]
public bool EnglishBool(string s)
{
if (_positives.Contains(s))
{
return true;
}
if (_negatives.Contains(s))
{
return false;
}
throw new InvalidOperationException("Couldn't create a bool from "+s);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment