Commit dd6c2d3e authored by Michael Herndon's avatar Michael Herndon

PROTO: flex

- fix a bug for IsNullableOfT
- fix a bug in Visit that didn't account for IsNullableOfT
- add VisitComplexObject_Simple
parent b7d1f4a3
......@@ -40,7 +40,7 @@ namespace NerdyMishka.Reflection.Extensions
public static bool IsNullableOfT(this IType type)
{
if(!type.ClrType.IsGenericTypeDefinition)
if(!type.ClrType.IsGenericType)
return false;
bool searched = type.HasFlag("Searched:IsNullable");
......@@ -48,11 +48,18 @@ namespace NerdyMishka.Reflection.Extensions
return type.HasFlag("INullable<>");
var query = typeof(Nullable<>);
var result = type.ClrType == query;
var result = false;
if(type.ClrType.IsGenericType && !type.ClrType.IsGenericTypeDefinition)
{
if(type.ClrType.GetGenericTypeDefinition() == query)
{
result = true;
}
}
if(result && type is IUnderlyingType)
{
var arg = type.ClrType.GetGenericArguments()[0];
var t = ReflectionCache.GetOrAdd(arg);
var t = arg.AsTypeInfo();
((IUnderlyingType)type).UnderlyingType = t;
if(type is IItemType)
((IItemType)type).ItemType = t;
......
......@@ -48,6 +48,9 @@ namespace NerdyMishka.Extensions.Flex
if(type.IsDataType)
return this.VisitValue(value, property, type);
if(type.IsNullableOfT() && type.UnderlyingType.IsDataType)
return this.VisitValue(value, property, type);
if(type.IsDictionaryLike())
return this.VisitDictionary((IDictionary)value, property, type);
......@@ -188,8 +191,6 @@ namespace NerdyMishka.Extensions.Flex
foreach(var key in dictionary.Keys)
{
var symbol = this.ConvertToSymbol(key.ToString());
var value = dictionary[key];
if(updateType && value != null)
......
......@@ -11,6 +11,50 @@ namespace Tests
public class YamlObjectWriterTests
{
[Fact]
public static void VisitComplexObject_Simple()
{
var configuration = new SimpleConfigurationValues();
var typeInfo = configuration.GetType().AsTypeInfo();
var writer = new YamlObjectWriter();
var node = writer.VisitComplexObject(configuration, null, typeInfo);
Assert.NotNull(node);
Assert.IsType<YamlMappingNode>(node);
var map = (YamlMappingNode)node;
foreach(var set in map.Children)
{
var key = ((YamlScalarNode)set.Key).Value;
key = key[0].ToString().ToUpperInvariant() + key.Substring(1);
var value = configuration.GetValue<object>(key);
Assert.IsType<YamlScalarNode>(set.Value);
var scalar = (YamlScalarNode)set.Value;
if(value == null)
{
Assert.Equal("null", scalar.Value);
continue;
}
switch(value)
{
case byte[] bytes:
Assert.Equal(Convert.ToBase64String(bytes), scalar.Value);
break;
case char[] chars:
Assert.Equal(new string(chars), scalar.Value);
break;
default:
Assert.Equal(value.ToString(), scalar.Value);
break;
}
}
}
[Fact]
public static void VisitDictionary_Simple()
{
......@@ -37,7 +81,6 @@ namespace Tests
Assert.Equal(value.ToString(), ((YamlScalarNode)set.Value).Value);
}
}
......@@ -150,17 +193,6 @@ namespace Tests
}
}
public class SimpleConfigurationWithList
{
public List<string> Values { get; set; } = new List<string>() {
"1",
"2",
"3",
"4",
"5",
"6"
};
}
public class SimpleConfigurationAttributes
{
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment