Fixed ListUserData type being unknown

This commit is contained in:
Deukhoofd 2019-01-21 14:03:11 +01:00
parent e74d061177
commit 47a80d2153
No known key found for this signature in database
GPG Key ID: B4C087AC81641654
1 changed files with 15 additions and 2 deletions

View File

@ -1,6 +1,7 @@
using System; using System;
using System.Collections; using System.Collections;
using System.Collections.Generic; using System.Collections.Generic;
using System.Collections.Immutable;
using Upsilon.BaseTypes.Number; using Upsilon.BaseTypes.Number;
using Upsilon.BaseTypes.ScriptTypeInterfaces; using Upsilon.BaseTypes.ScriptTypeInterfaces;
using Upsilon.BoundTypes; using Upsilon.BoundTypes;
@ -18,7 +19,16 @@ namespace Upsilon.BaseTypes.UserData
public ListUserData(IList list) public ListUserData(IList list)
{ {
List = list; List = list;
TypeName = BoundTypeHandler.GetTypeName(list.GetType()); var type = list.GetType();
if (type.IsArray)
{
TypeName = BoundTypeHandler.GetTypeName(type.GetElementType());
}
else
{
var generic = type.GetGenericArguments()[0];
TypeName = BoundTypeHandler.GetTypeName(generic);
}
} }
public ScriptType Get(Diagnostics diagnostics, TextSpan span, ScriptType index, EvaluationScope scope) public ScriptType Get(Diagnostics diagnostics, TextSpan span, ScriptType index, EvaluationScope scope)
@ -78,7 +88,10 @@ namespace Upsilon.BaseTypes.UserData
} }
} }
public override TypeContainer Type => new TypeContainer(TypeName); public override TypeContainer Type => new CompositeTypeContainer()
{
Types = new TypeContainer[]{BaseTypes.Type.Number, new TypeContainer(TypeName)}.ToImmutableArray()
};
public override object ToCSharpObject() public override object ToCSharpObject()
{ {
return List; return List;