Make Script conversion at end of execution use Type Binder, general Type Binder fixes
This commit is contained in:
@@ -35,7 +35,6 @@ namespace Upsilon.BaseTypes.UserData
|
||||
|
||||
public bool IsValidMatch(MethodBase match, ref object[] args)
|
||||
{
|
||||
var validMatch = true;
|
||||
var parameters = match.GetParameters();
|
||||
for (var i = 0; i < parameters.Length; i++)
|
||||
{
|
||||
@@ -54,7 +53,7 @@ namespace Upsilon.BaseTypes.UserData
|
||||
switch (typeCode)
|
||||
{
|
||||
case TypeCode.Boolean:
|
||||
if (argument is ScriptBoolean b)
|
||||
if (argument is ScriptBoolean)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
@@ -62,7 +61,7 @@ namespace Upsilon.BaseTypes.UserData
|
||||
break;
|
||||
case TypeCode.Char:
|
||||
case TypeCode.String:
|
||||
if (argument is ScriptString s)
|
||||
if (argument is ScriptString)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
@@ -79,7 +78,7 @@ namespace Upsilon.BaseTypes.UserData
|
||||
case TypeCode.UInt16:
|
||||
case TypeCode.UInt32:
|
||||
case TypeCode.UInt64:
|
||||
if (argument is ScriptNumber numeric)
|
||||
if (argument is ScriptNumber)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
@@ -107,7 +106,7 @@ namespace Upsilon.BaseTypes.UserData
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return validMatch;
|
||||
return true;
|
||||
}
|
||||
|
||||
public override object ChangeType(object value, System.Type type, CultureInfo culture)
|
||||
@@ -116,6 +115,13 @@ namespace Upsilon.BaseTypes.UserData
|
||||
{
|
||||
return value;
|
||||
}
|
||||
// ReSharper disable once ConditionIsAlwaysTrueOrFalse
|
||||
if (value == null)
|
||||
// ReSharper disable once HeuristicUnreachableCode
|
||||
{
|
||||
// ReSharper disable once HeuristicUnreachableCode
|
||||
return null;
|
||||
}
|
||||
|
||||
var typeCode = System.Type.GetTypeCode(type);
|
||||
switch (typeCode)
|
||||
@@ -181,7 +187,7 @@ namespace Upsilon.BaseTypes.UserData
|
||||
var dictionary = (IDictionary)Activator.CreateInstance(requiredDictionaryType);
|
||||
foreach (var variable in table.EvaluationScope.Variables)
|
||||
{
|
||||
dictionary.Add(variable.Key, variable.Value.ToCSharpObject());
|
||||
dictionary.Add(variable.Key, ChangeType(variable.Value, requiredDictionaryType, culture));
|
||||
}
|
||||
return dictionary;
|
||||
}
|
||||
@@ -200,12 +206,18 @@ namespace Upsilon.BaseTypes.UserData
|
||||
var list = (IList)Activator.CreateInstance(requiredListType);
|
||||
foreach (var variable in table.EvaluationScope.Variables)
|
||||
{
|
||||
list.Add(variable.Value.ToCSharpObject());
|
||||
list.Add(ChangeType(variable.Value, requiredListType, culture));
|
||||
}
|
||||
return list;
|
||||
}
|
||||
|
||||
return table.EvaluationScope.Variables.Select(x => x.Value.ToCSharpObject()).ToArray();
|
||||
else
|
||||
{
|
||||
var elementType = type.GetElementType();
|
||||
var input = table.EvaluationScope.Variables.Select(x => ChangeType(x.Value, elementType, culture)).ToArray();
|
||||
var array = Array.CreateInstance(elementType, input.Length);
|
||||
input.CopyTo(array, 0);
|
||||
return array;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user