Example #1
0
        public static NSPredicate ToPredicate(this Expressions.Expression expression)
        {
            var json = JsonConvert.SerializeObject(expression.ToArray());

#if DEBUG
            System.Diagnostics.Debug.WriteLine(json);
#endif

            var obj = NSJsonSerialization.Deserialize(NSData.FromString(json), 0, out var error);

            if (error != null)
            {
#if DEBUG
                System.Diagnostics.Debug.WriteLine(error.UserInfo.DebugDescription);
#endif
                return(null);
            }

            if (obj is NSArray array)
            {
                var result = ToPredicate(array);

#if DEBUG
                System.Diagnostics.Debug.WriteLine(result.ToString());
#endif

                return(result);
            }

            return(null);
        }
Example #2
0
        }                                         // Like a linked list, points to the next else (could be an 'else if' if it has a Condition)

        public IfStatement(SourceSpan span, Expressions.Expression condition, InstructionStatement body, IfStatement elseStatement)
        {
            this.Span          = span;
            this.Condition     = condition;
            this.Body          = body;
            this.ElseStatement = elseStatement;
        }
Example #3
0
 public ForEachStatement(SourceSpan span, Token variable, Expressions.Expression collection, InstructionStatement body)
 {
     this.Span       = span;
     this.Variable   = variable;
     this.Collection = collection;
     this.Body       = body;
 }
Example #4
0
 public CompiledNode(Expressions.Expression original, Expression tree, CodeNode[] dynamicValues)
     : base(original._left, original._right, original._tempContainer == null)
 {
     if (_tempContainer == null)
     {
         _tempContainer = original._tempContainer;
     }
     this._original      = original;
     this._tree          = tree;
     this._dynamicValues = dynamicValues;
 }
Example #5
0
        public void NullableTest()
        {
            var f1 = new Expressions.KVFieldExpression(1, EntityFieldType.Int32);
            var f2 = new Expressions.KVFieldExpression(2, EntityFieldType.Guid);

            Expressions.Expression exp = f1 > 5 & f2 == null;
            var expString1             = exp.ToString();

            var linqExp    = exp.ToLinqExpression(TestHelper.GetMockExpressionContext());
            var expString2 = linqExp.ToString();
        }
Example #6
0
        public ConditionalNode(Token token, Scopes.Scope scope, Expressions.Expression expression) : base(token)
        {
            Expression = expression;

            if (Expression.ReturnType != Nodes.Value.BoolValueNode.Type)
            {
                throw new Exceptions.TypeException(Expression.DefiningToken, Expression.ReturnType, Nodes.Value.BoolValueNode.Type);
            }

            Scope = new Scopes.Scope(scope);
        }
Example #7
0
        private byte[] SerializeExpression(Expressions.Expression exp)
        {
            byte[] data = null;
            using (var ms = new MemoryStream(1024))
            {
                var cf = new BinSerializer(ms);
                try { cf.Serialize(exp); }
                catch (Exception) { throw; }
                finally { cf.Clear(); }

                ms.Close();
                data = ms.ToArray();
            }
            return(data);
        }
Example #8
0
        static IOrderedQueryable <T> ApplyOrder <T>(
            IQueryable <T> source,
            string property,
            string methodName)
        {
            ;

            string[] props = property.Split(new char[] { ',', ';' });
            Type     type  = typeof(T);

            Expressions.ParameterExpression arg =
                Expressions.Expression.Parameter(type, "x");

            Expressions.Expression expr = arg;
            foreach (string prop in props)
            {
                // use reflection (not ComponentModel) to mirror LINQ
                Reflection.PropertyInfo pi = type.GetProperty(prop);
                if (pi == null)
                {
                    Reflection.FieldInfo fi = type.GetField(prop);
                    expr = Expressions.Expression.Field(expr, fi);
                    type = fi.FieldType;
                }
                else
                {
                    expr = Expressions.Expression.Property(expr, pi);
                    type = pi.PropertyType;
                }
            } // Next prop

            Type delegateType = typeof(Func <,>).MakeGenericType(typeof(T), type);

            Expressions.LambdaExpression lambda =
                Expressions.Expression.Lambda(delegateType, expr, arg);

            object result = typeof(Queryable).GetMethods().Single(
                method => method.Name == methodName &&
                method.IsGenericMethodDefinition &&
                method.GetGenericArguments().Length == 2 &&
                method.GetParameters().Length == 2)
                            .MakeGenericMethod(typeof(T), type)
                            .Invoke(null, new object[] { source, lambda });

            return((IOrderedQueryable <T>)result);
        } // End Function ApplyOrder
 /// <summary>
 /// Initialize a new instance of the <see cref="ClassDeclarationStatement"/> class using the specified parameters.
 /// </summary>
 /// <param name="linePragma">The position of the statement in the script code.</param>
 /// <param name="name">The name of the class.</param>
 /// <param name="super">The type expression of the super class.</param>
 /// <param name="members">The members of the class.</param>
 /// <exception cref="ArgumentNullException"><paramref name="linePragma"/> or <pararef name="name"/> is <see langword="null"/>.</exception>
 /// <exception cref="ArgumentException"><pararef name="name"/> is empty or white space.</exception>
 public ClassDeclarationStatement(
     LinePragma linePragma, string name, Expressions.Expression super,
     MemberCollection members)
     : base(linePragma)
 {
     if (name == null)
     {
         throw new ArgumentNullException();
     }
     if (string.IsNullOrWhiteSpace(name))
     {
         throw new ArgumentException(ExceptionResource.InvalidIdentifier);
     }
     Name    = name;
     Super   = super;
     Members = members;
 }
Example #10
0
        public unsafe void KVFieldExpressionTest_Mvcc()
        {
            var data  = StringHelper.FromHexString("00000020E4D8BEBE75592200000080000600004141414141310501880100000000000000000002060000414141414131");
            var field = new Expressions.KVFieldExpression(Consts.EMPLOEE_NAME_ID, EntityFieldType.String);

            Expressions.Expression filter = field == "AAAAA1";

            var ctx  = TestHelper.GetMockExpressionContext();
            var body = filter.ToLinqExpression(ctx);
            var exp  = Expression.Lambda <KVFilterFunc>(body,
                                                        ctx.GetParameter("vp"), ctx.GetParameter("vs"), ctx.GetParameter("mv"), ctx.GetParameter("ts"));
            var func = exp.Compile();

            fixed(byte *ptr = data)
            {
                IntPtr dataPtr = new IntPtr(ptr);

                Assert.True(func(dataPtr, data.Length, true, ulong.MaxValue));
            }
        }
Example #11
0
        public unsafe void KVFieldExpressionTest_NoneMvcc()
        {
            var data  = StringHelper.FromHexString("400005000041646D696E800005000041646D696E");
            var field = new Expressions.KVFieldExpression(Consts.EMPLOEE_NAME_ID, EntityFieldType.String);

            Expressions.Expression filter = field == "Admin";

            var ctx  = TestHelper.GetMockExpressionContext();
            var body = filter.ToLinqExpression(ctx);
            var exp  = Expression.Lambda <KVFilterFunc>(body,
                                                        ctx.GetParameter("vp"), ctx.GetParameter("vs"), ctx.GetParameter("mv"), ctx.GetParameter("ts"));
            var func = exp.Compile();

            fixed(byte *ptr = data)
            {
                IntPtr dataPtr = new IntPtr(ptr);

                Assert.True(func(dataPtr, data.Length, false, 0));
            }
        }
Example #12
0
 protected override Expressions.Expression Prepare(Expressions.Expression expression)
 => base.Prepare(expression).ReplaceIncludeMethodCall();
Example #13
0
 public AssignmentStatement(Expressions.Expression target, Expressions.Expression value)
 {
     this.Target = target;
     this.Value  = value;
 }
 public InvalidExpressionException(Expressions.Expression expression) : base(string.Format($"{expression} is not valid"))
 {
 }
Example #15
0
 public ExpressionStatement(Expressions.Expression expression)
 {
     this.Expression = expression;
 }
Example #16
0
 public ReturnStatement(Token returnKeyword, Expressions.Expression value)
 {
     this.ReturnKeyword = returnKeyword;
     this.Value         = value;
 }
Example #17
0
 public Collection(FieldType type, Expressions.Expression size)
 {
     this.Size = size;
     this.Type = type;
 }
Example #18
0
 public AsciiString(Expressions.Expression size)
 {
     this.Size = size;
 }
 public ulong Visit(Expressions.Expression x)
 {
     return(1000847);
 }
Example #20
0
 public DoWhileStatement(SourceSpan span, InstructionStatement body, Expressions.Expression condition)
 {
     this.Span      = span;
     this.Condition = condition;
     this.Body      = body;
 }
Example #21
0
 public IfConditionNode(Token token, Scopes.Scope scope, Expressions.Expression expression) : base(token, scope, expression)
 {
 }
Example #22
0
 public VariableDeclarationStatement(SourceSpan span, Token name, Expressions.Expression initializer)
 {
     this.Span        = span;
     this.Name        = name;
     this.Initializer = initializer;
 }
 public ExpressionStatement(Expressions.Expression expression) : base(expression.token)
 {
     this.expression = expression;
 }