public override void Evaluate(IScriptContext context) { if (TypeExpr == null && GenericsPostfix == null) { context.Result = RuntimeHost.GetType(Identifier); return; } if (TypeExpr != null) { string name = string.Format("{0}.{1}", EvaluateName(TypeExpr), Identifier); Type type = null; if (GenericsPostfix != null) { Type genericType = RuntimeHost.GetType(GenericsPostfix.GetGenericTypeName(name)); GenericsPostfix.Evaluate(context); type = genericType.MakeGenericType((Type[])context.Result); } else { type = RuntimeHost.GetType(name); } context.Result = type; } else { Type genericType = RuntimeHost.GetType(Identifier); GenericsPostfix.Evaluate(context); context.Result = genericType.MakeGenericType((Type[])context.Result); } }
private void EvaluateGenericType(IScriptContext context) { ScriptGenericsPostfix genericPostfix = (ScriptGenericsPostfix)Modifiers.First(); Type genericType = GetIndentifierValue(context, genericPostfix.GetGenericTypeName(Identifier)) as Type; if (genericType == null || !genericType.IsGenericType) { throw new ScriptException("Given type is not generic"); } genericPostfix.Evaluate(context); context.Result = genericType.MakeGenericType((Type[])context.Result); }
public ScriptTypeExpr(AstNodeArgs args) : base(args) { if (ChildNodes.Count == 2 && ChildNodes[1].ChildNodes.Count == 0) { Identifier = ((Token)ChildNodes[0]).Text; } else if (ChildNodes[0] is ScriptTypeExpr) { TypeExpr = ChildNodes[0] as ScriptTypeExpr; Identifier = (ChildNodes[2].ChildNodes[0] as Token).Text; GenericsPostfix = ChildNodes[2].ChildNodes[1] as ScriptGenericsPostfix; } else { GenericsPostfix = (ScriptGenericsPostfix)ChildNodes[1]; Identifier = GenericsPostfix.GetGenericTypeName(((Token)ChildNodes[0]).Text); } }