Skip to content

Commit

Permalink
Merge pull request #93 from antmt/dynamic-bool-support
Browse files Browse the repository at this point in the history
Added in support for boolean values in Dynamic Yaml
  • Loading branch information
aaubry committed Mar 13, 2014
2 parents f15a480 + 2834c4b commit 4efc1f6
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 1 deletion.
14 changes: 14 additions & 0 deletions YamlDotNet.Dynamic.Test/DynamicYamlTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,19 @@ public void TestNonexistingMember()
id.Should().NotHaveValue();
}

[Fact]
public void TestBool()
{
dynamic dynamicYaml = new DynamicYaml(MappingYaml);

bool[] values = dynamicYaml.valid;

values[0].Should().BeTrue();
values[1].Should().BeTrue();
values[2].Should().BeFalse();
values[3].Should().BeFalse();
}

private const string EnumYaml = @"---
- stringComparisonMode: CurrentCultureIgnoreCase
- stringComparisonMode: Ordinal";
Expand All @@ -216,6 +229,7 @@ public void TestNonexistingMember()
private const string MappingYaml = @"---
receipt: Oz-Ware Purchase Invoice
date: 2007-08-06
valid: [true, True, False, false]
customer:
given: Dorothy
family: Gale
Expand Down
10 changes: 9 additions & 1 deletion YamlDotNet.Dynamic/DynamicYaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,8 @@ public class DynamicYaml : DynamicObject
typeof(long),
typeof(float),
typeof(double),
typeof(decimal)
typeof(decimal),
typeof(bool)
};


Expand Down Expand Up @@ -269,6 +270,13 @@ private bool TryConvertToBasicType(Type type, bool isNullable, out object result
result = success ? (object)decimalResult : null;
return success;
}
if (type == typeof(bool))
{
bool boolResult;
var success = bool.TryParse(scalarNode.Value, out boolResult);
result = success ? (object)boolResult : null;
return success;
}
if (type.IsEnum)
{
long longResult;
Expand Down

0 comments on commit 4efc1f6

Please sign in to comment.