Permalink
Browse files
BooleanFamily supports y/n syntax
- Loading branch information...
|
@@ -74,6 +74,24 @@ public void treats_on_string_as_true() |
|
|
WithValue("ON").ShouldBeTrue();
|
|
|
}
|
|
|
|
|
|
+ [Test]
|
|
|
+ public void treats_no_string_as_false()
|
|
|
+ {
|
|
|
+ WithValue("no").ShouldBeFalse();
|
|
|
+ WithValue("NO").ShouldBeFalse();
|
|
|
+ WithValue("n").ShouldBeFalse();
|
|
|
+ WithValue("N").ShouldBeFalse();
|
|
|
+ }
|
|
|
+
|
|
|
+ [Test]
|
|
|
+ public void treats_yes_string_as_true()
|
|
|
+ {
|
|
|
+ WithValue("yes").ShouldBeTrue();
|
|
|
+ WithValue("YES").ShouldBeTrue();
|
|
|
+ WithValue("y").ShouldBeTrue();
|
|
|
+ WithValue("Y").ShouldBeTrue();
|
|
|
+ }
|
|
|
+
|
|
|
[Test]
|
|
|
public void treats_empty_string_as_false()
|
|
|
{
|
|
|
|
|
@@ -1,5 +1,7 @@ |
|
|
using System;
|
|
|
+using System.Collections.Generic;
|
|
|
using System.ComponentModel;
|
|
|
+using System.Linq;
|
|
|
using System.Reflection;
|
|
|
|
|
|
namespace FubuCore.Binding
|
|
@@ -8,6 +10,7 @@ namespace FubuCore.Binding |
|
|
public class BooleanFamily : StatelessConverter
|
|
|
{
|
|
|
private static TypeConverter _converter = TypeDescriptor.GetConverter(typeof(bool));
|
|
|
+ private static IList<string> _aliases = new List<string> { "yes", "y" };
|
|
|
public const string CheckboxOn = "on";
|
|
|
|
|
|
public override bool Matches(PropertyInfo property)
|
|
@@ -25,6 +28,7 @@ public override object Convert(IPropertyContext context) |
|
|
|
|
|
return valueString.Contains(context.Property.Name)
|
|
|
|| valueString.EqualsIgnoreCase(CheckboxOn)
|
|
|
+ || _aliases.Any(x => x.Equals(valueString, StringComparison.OrdinalIgnoreCase))
|
|
|
|| (bool)_converter.ConvertFrom(rawValue);
|
|
|
}
|
|
|
}
|
|
|
0 comments on commit
4254574