示例#1
0
 public static PipeValue Length(PipeValue obj)
 {
     if (obj.IsEvallable)
     {
         if (obj.HasProperty("length"))
         {
             return(obj["length"]);
         }
     }
     return(0);
 }
示例#2
0
        public PipeValue Evaluate(EvaluationContext context, bool checkValid, out bool isValid)
        {
            CommonHelper.ConfirmNotNull(context, "context");
            isValid = true;
            PipeValue value = context.CurrentValue;

            if (this.Count > 0)
            {
                ConstantObjectPath m = this[0] as ConstantObjectPath;
                if (m != null)
                {
                    switch (m.Value)
                    {
                    case "#":
                        return(value.Value is PipeValuePropertyEnumerator ? ((PipeValuePropertyEnumerator)value.Value).CurrentKey : PipeValue.Undefined);

                    case "##":
                        return(value.Value is PipeValuePropertyEnumerator ? ((PipeValuePropertyEnumerator)value.Value).CurrentIndex : PipeValue.Undefined);

                    case "#count":
                        return(value.Value is PipeValuePropertyEnumerator ? ((PipeValuePropertyEnumerator)value.Value).Count : 0);
                    }
                }
            }
            value = value.Value is PipeValuePropertyEnumerator ? ((PipeValuePropertyEnumerator)value.Value).CurrentValue : value;
            if (this.Count > 0)
            {
                ConstantObjectPath m = this[0] as ConstantObjectPath;
                if (m != null)
                {
                    int  intValue;
                    bool hasPropertyName = value.IsEvallable && (value.Type != PipeValueType.Object ? value[m.Value] != PipeValue.Undefined : (value.HasProperty(m.Value) || (value.IsArray && Int32.TryParse(m.Value, out intValue))));
                    if (checkValid && !hasPropertyName && !context.Globals.ContainsKey(m.Value))
                    {
                        isValid = false;
                        return(value);
                    }
                    value = hasPropertyName ? value[m.Value] : context.Globals[m.Value];
                }
            }
            for (int i = 1, len = this.Count; i < len && value.IsEvallable; i++)
            {
                string name = this[i] is ConstantObjectPath ? ((ConstantObjectPath)this[i]).Value : (string)this[i].Evaluate(context);
                value = value[name];
            }
            return(value);
        }