tlang-interperter-cs/MemberGetValueNode.cs

50 lines
1.2 KiB
C#
Raw Normal View History

2023-03-09 19:40:14 +00:00
namespace tlang
{
public class MemberGetVariableValue : GetVariableValue
{
public Node Parent {get;set;}
public MemberGetVariableValue(Node parent,string text) : base(text)
{
Parent = parent;
}
public override TObject Execute(IScopeEnvironment nodeEnv)
{
var res=Parent.Execute(nodeEnv);
var dict = res as TDictionary;
var integer = res as TNumber;
var array = res as TArray;
if(array != null)
{
if(Name == "length" || Name == "count")
{
return new TNumber(array.Items.Count);
}
}
if(dict != null)
{
if(dict.MemberExists($"get{Name}"))
{
var mbm= dict[$"get{Name}"] as ICallable;
if(mbm != null)
return mbm.Call();
}
if(dict.MemberExists(Name))
{
return dict[Name];
}
}
if(integer != null)
{
}
return new TUninit();
}
}
}