Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 934723
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T21:02:46+00:00 2026-05-15T21:02:46+00:00

I’m working on some expression tree code written by a colleague and am looking

  • 0

I’m working on some expression tree code written by a colleague and am looking into the possibility of adding additional expressions. It currently supports: equals, not-equals, IsNull etc. I need to add something that will allow it to use a wildcard comparison similar to the SQL “Like” command or using regular expressions. At the moment the code parses an XML file and extracts the data which is then processed using code similar to the line shown below. This is an example of the “Equal” expression. “callExp” is a MemberExpression that basically holds the field name of my table (Entities) and GetConstantExpression gets details about the data I am comparing.

xRet = Expression.MakeBinary(ExpressionType.Equal, callExp, GetConstantExpression(element.Element("Value"), callExp.Type));

What I’m after is a way to create an “Expression” that is similar to the “Like” command. Can this be done using a few lines similar to above or is this going to be more complex? Any good resources that could help in this area?

==================================================================================

New code based on feedback:

I was looking at some examples and tried the following which I was hoping would create me an Expression. It gives me the error shown below. Am I going in the right direction to create a “StartsWith” expression? _entityExp is a ParameterExpression reference to MyClass.

ParameterExpression p = Expression.Parameter(_entityExp.Type, "entity");
MethodInfo method = typeof(string).GetMethod("StartsWith", new[] { typeof(string) });
var containsMethodExp = Expression.Call(p, method, Expression.Constant("root"), p);

Method ‘Boolean StartsWith(System.String)’ declared on type ‘System.String’ cannot be called with instance of type ‘MyClass’

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-15T21:02:47+00:00Added an answer on May 15, 2026 at 9:02 pm

    Expression trees can only represent the same sort of functionality as you get in .NET languages – method calls, property evaluation etc.

    The closest you normally get to “like” is to call string.StartsWith, string.EndsWith or string.Contains. If you want to deal with regular expressions instead, you might want to use Regex.IsMatch instead. Either way, this is something which is encapsulated in methods rather than in the “language” of expression trees itself.

    Without knowing more about how your expression trees are consumed, it’s hard to say exactly what you should do. You could create your own “Like” method which the consumer would notice and handle appropriately, for example… or you could use the existing string/regex methods.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Need some regular expressions help. So far I have my code working to allow
I'm working some code that inserts csv rows into an SQLite database using Python.
I working with some regular expression matching and I'm trying to figure out how
I really need some help in Regular Expressions, i'm working on a function like
I've been re-working some code due to a memory leak. The code is part
Working on some code for a machine problem; we've just started working with pointers,
After working on some test code for open ID authentication, I had a break
Whilst working on some generally horrible Javascript code this morning, I came across the
I am building up a MGrammar spec to parse some pseudo code looking for
I'm using JavaScript to do some regular expression. Considering I'm working with well-formed source,

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.