예제 #1
0
        public static object ElementAt(object items, object index)
        {
            var arr = items as SequenceValue;

            if (arr != null)
            {
                if (!(index is decimal))
                {
                    return(Undefined.Value);
                }

                var dec = (decimal)index;
                if (dec != Math.Floor(dec))
                {
                    return(Undefined.Value);
                }

                var idx = (int)dec;
                if (idx >= arr.Elements.Count())
                {
                    return(Undefined.Value);
                }

                return(Representation.Represent(arr.Elements.ElementAt(idx)));
            }

            var dict = items as StructureValue;

            if (dict != null)
            {
                var s = index as string;
                if (s == null)
                {
                    return(Undefined.Value);
                }

                LogEventPropertyValue value;
                if (!LinqExpressionCompiler.TryGetStructurePropertyValue(dict, s, out value))
                {
                    return(Undefined.Value);
                }

                return(Representation.Represent(value));
            }

            return(Undefined.Value);
        }
        public static object _Internal_In(object item, object collection)
        {
            if (collection is SequenceValue arr)
            {
                for (var i = 0; i < arr.Elements.Count; ++i)
                {
                    if (UnboxedEqualHelper(Representation.Represent(arr.Elements[i]), item))
                    {
                        return(true);
                    }
                }

                return(false);
            }

            return(Undefined.Value);
        }
        public static object _Internal_Any(object items, object predicate)
        {
            if (!(predicate is Func <object, object> pred))
            {
                return(Undefined.Value);
            }

            if (items is SequenceValue arr)
            {
                return(arr.Elements.Any(e => true.Equals(pred(Representation.Represent(e)))));
            }

            if (items is StructureValue structure)
            {
                return(structure.Properties.Any(e => true.Equals(pred(Representation.Represent(e.Value)))));
            }

            return(Undefined.Value);
        }