|
|
@@ -555,13 +555,6 @@ namespace InABox.Core
|
|
|
return Enum.ToObject(type, value);
|
|
|
}
|
|
|
|
|
|
- if (!type.GetTypeInfo().IsInterface && type.GetTypeInfo().IsGenericType)
|
|
|
- {
|
|
|
- var innerType = type.GetTypeInfo().GetGenericArguments()[0];
|
|
|
- var innerValue = ChangeType(value, innerType);
|
|
|
- return Activator.CreateInstance(type, innerValue);
|
|
|
- }
|
|
|
-
|
|
|
if (value is string && type == typeof(Guid))
|
|
|
try
|
|
|
{
|
|
|
@@ -572,16 +565,19 @@ namespace InABox.Core
|
|
|
return Guid.Empty;
|
|
|
}
|
|
|
|
|
|
- if (value is IEnumerable<object?> objList)
|
|
|
+ if (value is string && type == typeof(byte[]))
|
|
|
+ return Convert.FromBase64String(value as string);
|
|
|
+
|
|
|
+ if (value is IEnumerable objList)
|
|
|
{
|
|
|
if(type == typeof(Guid))
|
|
|
{
|
|
|
- return objList.Select(x => ChangeType<Guid>(x)).ToArray();
|
|
|
+ return objList.Cast<object?>().Select(x => ChangeType<Guid>(x)).ToArray();
|
|
|
}
|
|
|
else if (type.IsArray)
|
|
|
{
|
|
|
var elementType = type.GetElementType();
|
|
|
- var collection = value as ICollection<object?> ?? objList.ToList();
|
|
|
+ var collection = value as ICollection<object?> ?? objList.Cast<object?>().ToList();
|
|
|
|
|
|
var arr = Array.CreateInstance(elementType, collection.Count);
|
|
|
var i = 0;
|
|
|
@@ -592,6 +588,32 @@ namespace InABox.Core
|
|
|
}
|
|
|
return arr;
|
|
|
}
|
|
|
+ else if (type.IsGenericType)
|
|
|
+ {
|
|
|
+ var typeDef = type.GetGenericTypeDefinition();
|
|
|
+ if(typeDef == typeof(Dictionary<,>))
|
|
|
+ {
|
|
|
+ var dict = (Activator.CreateInstance(type) as IDictionary)!;
|
|
|
+ var dictDef = type.GetSuperclassDefinition(typeof(Dictionary<,>))!;
|
|
|
+ var keyType = dictDef.GenericTypeArguments[0];
|
|
|
+ var valType = dictDef.GenericTypeArguments[1];
|
|
|
+ if(value is IDictionary fromDict)
|
|
|
+ {
|
|
|
+ foreach(DictionaryEntry entry in fromDict)
|
|
|
+ {
|
|
|
+ dict[ChangeType(entry.Key, keyType)] = ChangeType(entry.Value, valType);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return dict;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ if (!type.GetTypeInfo().IsInterface && type.GetTypeInfo().IsGenericType)
|
|
|
+ {
|
|
|
+ var innerType = type.GetTypeInfo().GetGenericArguments()[0];
|
|
|
+ var innerValue = ChangeType(value, innerType);
|
|
|
+ return Activator.CreateInstance(type, innerValue);
|
|
|
}
|
|
|
|
|
|
if (value is byte[] && type == typeof(Guid))
|
|
|
@@ -615,9 +637,6 @@ namespace InABox.Core
|
|
|
//if (value is JArray && type == typeof(string[]))
|
|
|
// return (value as JArray).Select(x => x.ToString()).ToArray();
|
|
|
|
|
|
- if (value is string && type == typeof(byte[]))
|
|
|
- return Convert.FromBase64String(value as string);
|
|
|
-
|
|
|
if(value is FilterConstant constant)
|
|
|
{
|
|
|
if (type == typeof(DateTime))
|