private object GetFirstObjectFromMember(ExprNode memberExp, List<Node> suffixes)
{
if (memberExp is SelfExpression)
{
return Context.CurrentFrame.Resolve("this");
}
if (memberExp is Identifier)
{
var id = ((Identifier)memberExp).Value;
if (Context.CurrentFrame.Exist(id))
return Context.CurrentFrame.Resolve(id);
// TODO handle nested type
// propably CLR type
if (!(suffixes[0] is TypeDescriptorSuffix) && Context.IsClrType(id))
return Context.LoadTypeFromName(id);
// start with namespace? attempt further
for (int i = 0; i < suffixes.Count; i++)
{
var suffix = suffixes[i];
if (suffix is IndexSuffix)
break;
if (suffix is TypeDescriptorSuffix)
{
var typeParams = (Type[])suffix.Accept(this);
suffixes.RemoveRange(0, i + 1);
return Context.LoadTypeFromName(id, typeParams);
}
id += "." + suffix.SuffixValue(this);
if (i < suffixes.Count - 1 && (suffixes[i + 1] is TypeDescriptorSuffix))
{
var typeParams = (Type[])suffixes[i + 1].Accept(this);
suffixes.RemoveRange(0, i + 2);
return Context.LoadTypeFromName(id, typeParams);
}
if (Context.IsClrType(id))
{
suffixes.RemoveRange(0, i + 1);
return Context.LoadTypeFromName(id);
}
}
if (id.IndexOf('.') >= 0)
id = id.Substring(0, id.IndexOf('.'));
throw ErrorFactory.CreateNotDefinedError(id);
}
return memberExp.Accept(this);
}