Announcement

Collapse
No announcement yet.

Expression Tree

Collapse
X
  • Filter
  • Time
  • Show
Clear All
new posts

    Expression Tree

    I see expression trees are not supported, namely Expression.Labmda, Expression.And, etc. I sort of understand that having complete JavaScript engine under the tips of our fingers it might not be necessary that much but in my case, I work on a part of the application compiling expression trees from the database data. Compiled expression is supposed to be used for monitoring certain conditions on the servers side but on the client side I need exactly the same expression for input validation. I assume lack of this functionality suggests using something like Script.Eval and building a string expression but that will need two different logics to build it. So my point it would be great to have the ability to compose and run expression trees which provide certain level of abstraction and reusing of the code.

    #2
    Hi,

    Bridge supports expressions tree (including Expression.Lambda and Expression.And), see
    https://github.com/bridgedotnet/Brid.../Expression.cs

    But compilation of tree is not implemented yet
    It is in our TODO list

    Comment


      #3
      Strange... First of all if I try this code it does not find .Compilte()

               var compile = Expression.Lambda<Func<bool>>(
                  Expression.And(
                     Expression.Constant(true),
                     Expression.Constant(true)
                  )
               ).Compile();
      error CS1061: 'Expression<Func<bool>>' does not contain a definition for 'Compile' and no extension method 'Compile' accepting a first argument of type 'Expression<Func<bool>>' could be found (are you missing a using directive or an assembly reference?)

      But even if I remove .Compile() it complains on something

      Error: Member [CSharpInvocationResolveResult [Method System.Linq.Expressions.Expression.And(left:System .Linq.Expressions.Expression, right:System.Linq.Expressions.Expression):System.L inq.Expressions.BinaryExpression]] is marked as not usable from script at Bridge.Translator.MemberReferenceBlock.VisitMember ReferenceExpression()
      at Bridge.Translator.MemberReferenceBlock.EmitConvers ionExpression()
      at Bridge.Translator.ConversionBlock.DoEmit()
      at Bridge.Translator.AbstractEmitterBlock.Emit()
      at Bridge.Translator.Emitter.VisitMemberReferenceExpr ession(MemberReferenceExpression memberReferenceExpression)
      at ICSharpCode.NRefactory.CSharp.MemberReferenceExpre ssion.AcceptVisitor(IAstVisitor visitor)
      at Bridge.Translator.InvocationBlock.VisitInvocationE xpression()
      at Bridge.Translator.InvocationBlock.EmitConversionEx pression()
      at Bridge.Translator.ConversionBlock.DoEmit()
      at Bridge.Translator.AbstractEmitterBlock.Emit()
      at Bridge.Translator.Emitter.VisitInvocationExpressio n(InvocationExpression invocationExpression)
      at ICSharpCode.NRefactory.CSharp.InvocationExpression .AcceptVisitor(IAstVisitor visitor)
      at Bridge.Translator.InlineArgumentsBlock.<>c__Displa yClass32_0.<EmitInlineExpressionList>b__5(Match m)
      at System.Text.RegularExpressions.RegexReplacement.Re place(MatchEvaluator evaluator, Regex regex, String input, Int32 count, Int32 startat)
      at System.Text.RegularExpressions.Regex.Replace(Strin g input, MatchEvaluator evaluator, Int32 count, Int32 startat)
      at System.Text.RegularExpressions.Regex.Replace(Strin g input, MatchEvaluator evaluator)
      at Bridge.Translator.InlineArgumentsBlock.EmitInlineE xpressionList(ArgumentsInfo argsInfo, String inline, Boolean asRef, Boolean isNull, Nullable`1 definition)
      at Bridge.Translator.InlineArgumentsBlock.DoEmit()
      at Bridge.Translator.AbstractEmitterBlock.Emit()
      at Bridge.Translator.InvocationBlock.VisitInvocationE xpression()
      at Bridge.Translator.InvocationBlock.EmitConversionEx pression()
      at Bridge.Translator.ConversionBlock.DoEmit()
      at Bridge.Translator.AbstractEmitterBlock.Emit()
      at Bridge.Translator.Emitter.VisitInvocationExpressio n(InvocationExpression invocationExpression)
      at ICSharpCode.NRefactory.CSharp.InvocationExpression .AcceptVisitor(IAstVisitor visitor)
      at Bridge.Translator.VariableBlock.VisitVariableDecla rationStatement()
      at Bridge.Translator.VariableBlock.DoEmit()
      at Bridge.Translator.AbstractEmitterBlock.Emit()
      at Bridge.Translator.Emitter.VisitVariableDeclaration Statement(VariableDeclarationStatement variableDeclarationStatement)
      at ICSharpCode.NRefactory.CSharp.VariableDeclarationS tatement.AcceptVisitor(IAstVisitor visitor)
      at Bridge.Translator.Block.<>c__DisplayClass64_0.<DoE mitBlock>b__0(AstNode child)
      at System.Collections.Generic.List`1.ForEach(Action`1 action)
      at Bridge.Translator.Block.DoEmitBlock()
      at Bridge.Translator.Block.EmitBlock()
      at Bridge.Translator.Block.DoEmit()
      at Bridge.Translator.AbstractEmitterBlock.Emit()
      at Bridge.Translator.Emitter.VisitBlockStatement(Bloc kStatement blockStatement)
      at ICSharpCode.NRefactory.CSharp.BlockStatement.Accep tVisitor(IAstVisitor visitor)
      at Bridge.Translator.AsyncBlock.EmitAsyncBody()
      at Bridge.Translator.AsyncBlock.EmitAsyncBlock()
      at Bridge.Translator.AsyncBlock.DoEmit()
      at Bridge.Translator.AbstractEmitterBlock.Emit()
      at Bridge.Translator.VisitorMethodBlock.VisitMethodDe claration(MethodDeclaration methodDeclaration)
      at Bridge.Translator.VisitorMethodBlock.DoEmit()
      at Bridge.Translator.AbstractEmitterBlock.Emit()
      at Bridge.Translator.Emitter.VisitMethodDeclaration(M ethodDeclaration methodDeclaration)
      at Bridge.Translator.MethodBlock.EmitMethods(Dictiona ry`2 methods, Dictionary`2 properties, Dictionary`2 operators)
      at Bridge.Translator.MethodBlock.DoEmit()
      at Bridge.Translator.AbstractEmitterBlock.Emit()
      at Bridge.Translator.ClassBlock.EmitInstantiableBlock ()
      at Bridge.Translator.ClassBlock.DoEmit()
      at Bridge.Translator.AbstractEmitterBlock.Emit()
      at Bridge.Translator.EmitBlock.DoEmit()
      at Bridge.Translator.AbstractEmitterBlock.Emit()
      at Bridge.Translator.Emitter.Emit()
      at Bridge.Translator.Translator.Translate()
      at Bridge.Build.GenerateScript.Execute()
      Last edited by geoffrey.mcgill; 2017-03-25 @ 09:36 PM.

      Comment


        #4
        Hi,

        Strange... First of all if I try this code it does not find .Compilte()
        Yes, as I wrote compilation is not supported yet.

        Regarding, And method. Some expression methods require type information in Bridge implementation. Just check possible overloads. For And, you can use
        https://github.com/bridgedotnet/Brid...ession.cs#L306
        Last edited by geoffrey.mcgill; 2017-03-25 @ 09:37 PM.

        Comment


          #5
          Indeed there are overloads of And which built fine but then if .Compile() is not supported there is no way to execute the expression or am I missing something? How do I execute the expression?
          Last edited by geoffrey.mcgill; 2017-03-25 @ 09:38 PM.

          Comment

          Working...
          X