public void Reset() { CurrentIndex = -1; CurrentKey = String.Empty; CurrentValue = PipeValue.Undefined; enumerator = null; }
public static PipeValue[] CopyAsArray(this PipeValue arr) { if (arr.IsArray) { return(((IEnumerable)arr.Value).OfType <object>().Select(v => new PipeValue(v)).ToArray()); } return(new[] { arr }); }
public PipeValue[] TakeArguments(int count) { PipeValue[] arr = new PipeValue[count]; for (int i = 0; i < count; i++) { arr[i] = TakeArgument(); } return(arr); }
public void Add(PipeValue value, string key) { if (isArray) { array.Add(value.Value); } else { array.Add(new KeyValuePair <string, object>(key, value.Value)); } }
public static PipeValue Map(this PipeValue value, PipeLambda map) { CommonHelper.ConfirmNotNull(map, "map"); PipeValuePropertyEnumerator enumerator = value.GetEnumerator(); PipeValueObjectBuilder collection = new PipeValueObjectBuilder(value.IsArray); while (enumerator.MoveNext()) { collection.Add(map.Invoke(enumerator), enumerator.CurrentKey); } return(collection); }
protected override PipeValue InvokeInternal(PipeValue obj, PipeValue index) { try { Hashtable ht = new Hashtable { { index.ToString(), obj } }; IEnumerator enumerator = new PipeValue(ht).GetEnumerator(); enumerator.MoveNext(); pipe.context.PushObjectStack(enumerator); return(pipe.Evaluate()); } finally { pipe.context.PopObjectStack(); } }
public static PipeValue First(this PipeValue value, PipeLambda fn, bool returnBoolean = false, bool negate = false) { CommonHelper.ConfirmNotNull(fn, "fn"); PipeValuePropertyEnumerator enumerator = value.GetEnumerator(); while (enumerator.MoveNext()) { if (negate ^ (bool)fn.Invoke(enumerator)) { return(returnBoolean ? true : enumerator.CurrentValue); } } return(returnBoolean ? false : PipeValue.Undefined); }
public bool MoveNext() { if (enumerator == null) { enumerator = GetEnumerator(); } if (enumerator.MoveNext()) { CurrentIndex++; CurrentKey = (string)enumerator.Current; CurrentValue = GetValue(enumerator); return(true); } return(false); }
public static PipeValue Where(this PipeValue value, PipeLambda filter) { CommonHelper.ConfirmNotNull(filter, "filter"); PipeValuePropertyEnumerator enumerator = value.GetEnumerator(); PipeValueObjectBuilder collection = new PipeValueObjectBuilder(value.IsArray); while (enumerator.MoveNext()) { if ((bool)filter.Invoke(enumerator)) { collection.Add(enumerator.CurrentValue, enumerator.CurrentKey); } } return(collection); }
internal PipeValue Evaluate() { bool isValid; PipeValue input = ObjectPath.Empty.Evaluate(context); PipeValue value = (pipe.Count > start ? pipe[start].ObjectPath : ObjectPath.Empty).Evaluate(context, true, out isValid); List <PipeValue> returnArray = new List <PipeValue>(); i = start + (isValid ? 1 : 0); while (i <= end) { int startpos = i; string name = pipe[i++].TextValue; if (name == "|") { returnArray.Add(value); value = HasArgument(true) ? TakeArgument() : input; } else if (name == "&&" || name == "||") { if ((bool)value ^ (name == "&&")) { break; } PipeLambda fn = TakeFunction(); if (fn != null) { value = fn.Invoke(input); } else if (HasArgument(true)) { value = TakeArgument(); } else { value = input; } } else { this.Value = value; try { PipeFunction fn; try { fn = context.ResolveFunction(name); } catch (InvalidPipeFunctionException) { if (startpos == start) { value = PipeValue.Undefined; continue; } throw; } value = fn.Invoke(this); } catch (Exception ex) { if (ex is TargetInvocationException) { ex = ex.InnerException; } PipeExecutionException wrappedException = new PipeExecutionException(ex.Message, ex, new WaterpipeException.CallSite { InputString = context.InputString, ConstructStart = pipe.StartIndex, ConstructEnd = pipe.EndIndex, HighlightStart = pipe[startpos].StartIndex, HighlightEnd = pipe[i - 1].EndIndex }); context.AddException(wrappedException); } } } if (returnArray.Count > 0) { returnArray.Add(value); return(new PipeValueObjectBuilder(returnArray, true)); } return(value); }
public PipeLambda TakeArgumentAsConstantFunction() { PipeValue value = TakeArgument(); return(new PipeLambda((x, y) => value)); }
protected virtual PipeValue InvokeInternal(PipeValue obj, PipeValue index) { return(fn(obj, index)); }
public PipeValue Invoke(PipeValue obj, PipeValue index) { return(InvokeInternal(obj, index)); }
public PipeValue Invoke(PipeValue obj) { return(InvokeInternal(obj, PipeValue.Undefined)); }