private static object TakeArray <T>(RunContext ctx) { var list = new List <T>(); while (ctx.Tokens.PeekOrDefault() is StringToken strToken) { ctx.Tokens.Dequeue(); if (!ValueSetter.TryParseValue(strToken.Content, typeof(T), out var obj)) { throw new RunException($"Cannot parse value into {typeof(T).Name} at position {strToken.Position}"); } list.Add((T)obj); } return(list.ToArray()); }
private static bool TryTakeValue(ref RunContext ctx, Type valueType, [MaybeNullWhen(false)] out object value) { if (valueType.IsArray) { var del = (TakeArrayDelegate)typeof(YaclipApp).GetMethod(nameof(TakeArray), BindingFlags.NonPublic | BindingFlags.Static).MakeGenericMethod(valueType.GetElementType()).CreateDelegate(typeof(TakeArrayDelegate)); value = del(ctx); return(true); } if (!(ctx.Tokens.PeekOrDefault() is StringToken strToken)) { value = null; return(false); } ctx.Tokens.Dequeue(); return(ValueSetter.TryParseValue(strToken.Content, valueType, out value)); }