VS 2015 [RESOLVED] New Expressions.ConstantExpression??-VBForums
Results 1 to 3 of 3

Thread: [RESOLVED] New Expressions.ConstantExpression??

  1. #1

    Thread Starter
    PowerPoster i00's Avatar
    Join Date
    Mar 2002
    Location
    1/2 way accross the galaxy.. and then some
    Posts
    2,200

    Resolved [RESOLVED] New Expressions.ConstantExpression??

    I want to delcare a new Expressions.ConstantExpression...

    I was hoping that there was just a constructor like:
    Public Sub New Expressions.ConstantExpression(Value As Object)
    So I could go:
    New Expressions.ConstantExpression("K")
    And get something like:
    Name:  Const.jpg
Views: 131
Size:  15.2 KB

    ...Now I know that you are probably wondering why I want to do this ... so ... basically I am wanting to replace expressions with the proper const values... for eg:
    VB.Net Code:
    1. Dim ExpressionWithProperConsts =
    2.     Query.Expression.Visit(Function(p As Expressions.MemberExpression)
    3.                                If p.Expression.NodeType = Expressions.ExpressionType.Constant Then
    4.                                    Dim Value = Expressions.Expression.Lambda(p).Compile.DynamicInvoke()
    5.                                    Return New Expressions.ConstantExpression(Value)
    6.                                Else
    7.                                    Return p
    8.                                End If
    9.                            End Function)
    ... And yes I have my reasons ... so please don't say why

    EDIT:
    And before you ask.. the .Visit thing is an extension of mine that allows me to replace expressions within an expression tree... but it works basically the same way as any other standard visitor... Just a helper for me to replace parts of expressions easily.

    Thanks in advance,
    Kris

  2. #2
    .NUT jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    96,856

    Re: New Expressions.ConstantExpression??

    Have you read the documentation for the ConstantExpression class? It states:
    Use the Constant factory methods to create a ConstantExpression.
    It provides a link to the documentation for those methods and it provides a code example.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    MSDN "How Do I?" Videos: VB | C#
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  3. #3

    Thread Starter
    PowerPoster i00's Avatar
    Join Date
    Mar 2002
    Location
    1/2 way accross the galaxy.. and then some
    Posts
    2,200

    Re: New Expressions.ConstantExpression??

    Whops ... missed that

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Featured


Click Here to Expand Forum to Full Width

Survey posted by VBForums.