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

  • SEARCH
  • Home
  • 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 8268369
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T05:51:48+00:00 2026-06-08T05:51:48+00:00

static class QueryableExtensions { private static MethodInfo StringContainsMethod; private static MethodInfo StringStartsWithMethod; static QueryableExtensions()

  • 0
static class QueryableExtensions
{
private static MethodInfo StringContainsMethod;
private static MethodInfo StringStartsWithMethod;
static QueryableExtensions()
{
    Type[] singleStringParam = new[] { typeof(string) };
    StringContainsMethod = typeof(string).GetMethod("Contains", singleStringParam);
    StringStartsWithMethod = typeof(string).GetMethod("StartsWith", singleStringParam);
}
public static IQueryable<T> AppendTextFilter<T>(this IQueryable<T> queryable, Expression<Func<T, string>> memberSelector, string condition, string value)
{
    Expression expression = null;
    switch (condition)
    {
        case "StartsWith":
            expression = Expression.Call(memberSelector.Body, StringStartsWithMethod, Expression.Constant(value));
            break;
        case "Equals":
            expression = Expression.Equal(memberSelector.Body, Expression.Constant(value));
            break;
        case "Contains":
            expression = Expression.Call(memberSelector.Body, StringContainsMethod, Expression.Constant(value));
            break;
        default:
            throw new NotSupportedException(string.Format("'{0}' is not a supported condition", condition));
    }
    var lambda = Expression.Lambda<Func<T, bool>>(expression, memberSelector.Parameters);
    return queryable.Where(lambda);
}
}

When i search on google,I get above class.Well,it really help me a lot,But it still can’t meet my need.
The problem is that it can only process field of the type “string”. As you seen in the above block code ,the method can only process with T,string .
How I can process any type i want within a single method?

  • 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-06-08T05:51:50+00:00Added an answer on June 8, 2026 at 5:51 am

    well, the idea would be to replace string by a generic type, this way.

    public static IQueryable<T> AppendTextFilter<T, TValue>(
          this IQueryable<T> queryable, 
          Expression<Func<T, TValue>> memberSelector, 
          string condition, 
          TValue value)
    

    But with your sample, this doesn’t make much sense, as StartsWith, for example, can just be applied if TValue type is string…

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

Sidebar

Related Questions

public static class TestTask extends AsyncTask<Void, Integer, Integer> { private String stacktrace; public TestTask
private static class FilterByStringContains implements Predicate<String> { private String filterString; private FilterByStringContains(final String filterString)
The class looks as follows: public static class CacheManager { private static Dictionary<string, object>
public static class EmptyOrNullHelper public static string EmptyOrNull(this HtmlHelper helper, IQueryable(T) type) { //Code
I've placed a static class TestClass in the App_Code folder. The class contains a
Consider this code: public static class PredefinedStrings { public const string Golf = Golfing;
OK I have a static class that has two static members, a string and
public class DBAdapter { public static final String COLUMN_ID = ID; public static final
public static class MapClass extends MapReduceBase implements Mapper<LongWritable, Text, Text, IntWritable> { private Text
public static class Extensions { public static T Include<T>(this System.Enum type,T value) where T:struct

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.