Better handling of getting composite script types

This commit is contained in:
Deukhoofd 2019-01-21 13:37:51 +01:00
parent 86f47ae002
commit 44bfc90fe3
No known key found for this signature in database
GPG Key ID: B4C087AC81641654
1 changed files with 27 additions and 0 deletions

View File

@ -1,5 +1,7 @@
using System;
using System.Collections;
using System.Collections.Generic;
using System.Collections.Immutable;
using System.Linq;
using System.Reflection;
using Upsilon.BaseTypes.Number;
@ -140,6 +142,31 @@ namespace Upsilon.BaseTypes
return Type.Nil;
if (t == typeof(SimpleScriptTable))
return Type.Table;
if (t.IsArray)
{
var elementType = t.GetElementType();
return new CompositeTypeContainer()
{
Types = new TypeContainer[]{Type.Number, GetScriptType(elementType)}.ToImmutableArray()
};
}
if (typeof(IList).IsAssignableFrom(t))
{
var generic = t.GetGenericArguments()[0];
return new CompositeTypeContainer()
{
Types = new TypeContainer[]{Type.Number, GetScriptType(generic)}.ToImmutableArray()
};
}
if (typeof(IDictionary).IsAssignableFrom(t))
{
var key = t.GetGenericArguments()[0];
var value = t.GetGenericArguments()[1];
return new CompositeTypeContainer()
{
Types = new[]{GetScriptType(key), GetScriptType(value)}.ToImmutableArray()
};
}
if (typeof(IEnumerable).IsAssignableFrom(t))
return Type.Table;
if (typeof(IIndexable).IsAssignableFrom(t))