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 6096681
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T12:57:22+00:00 2026-05-23T12:57:22+00:00

I am modifying an open source program to create a generic filter for a

  • 0

I am modifying an open source program to create a generic filter for a datagrid in Silverlight. The code for the class is shown below.

    public PropertyData Property { get; set; }
    public FilterOperatorType FilterOperator { get; set; }
    public string FilterValue { get; set; }

    public Expression GetExpression<T>(ParameterExpression pe)
    {
        if (Property == null || Property.PropertyName == null)
            return null;
        PropertyInfo prop = typeof(T).GetProperty(Property.PropertyName);
        Expression left = Expression.Property(pe, prop);
        Expression right = null;

        switch (prop.PropertyType.Name)
        {
            case "String":
                right = Expression.Constant(FilterValue);
                break;
            case "Int32":
                int val;
                int.TryParse(FilterValue, out val);
                right = Expression.Constant(val);
                break;
            case "Int64":  
                int.TryParse(FilterValue, out val);
                Convert.ToInt32(val);        //does not work
                right = Expression.Constant(val);
                break;
            case "DateTime":
                DateTime dt;
                DateTime.TryParse(FilterValue, out dt);
                right = Expression.Constant(dt);
                break;
        }

        switch (FilterOperator)
        {
            case FilterOperatorType.Equal:
                return Expression.Equal(left, right);
            case FilterOperatorType.GreaterThan:
                return Expression.GreaterThan(left, right);
            case FilterOperatorType.GreaterThanOrEqual:
                return Expression.GreaterThanOrEqual(left, right);
            case FilterOperatorType.LessThan:
                return Expression.LessThan(left, right);
            case FilterOperatorType.LessThanOrEqual:
                return Expression.LessThanOrEqual(left, right);
            case FilterOperatorType.NotEqual:
                return Expression.NotEqual(left, right);
        }
        return null;
    }
}

Anytime I try to filter with an integer, I get an InvalidOperationException that state’s:
The binary operator Equal is not defined for the types ‘System.Int64’ and ‘System.Int32’.

I understand why this exception is being thrown, however on the example program for this code I don’t get any exceptions, due to the user’s inputed integer being of type Int32, while in my application it is an Int64. Anyone have any ideas on how to fix this?

  • 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-23T12:57:23+00:00Added an answer on May 23, 2026 at 12:57 pm

    You need to parse the input as a long rather than an int.

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

Sidebar

Related Questions

I'm modifying an open-source GUI (written in c) to add a new menu item
I am modifying a CMake file of an existing open source project written in
I'm modifying an open-source project that's stored in an SVN repo. Since my changes
I'm doing some contribution to an open source library, but I'm having trouble modifying
I am modifying some code and came across a declaration that I am having
I am modifying a SQL table through C# code and I need to drop
I'm modifying existing security code. The specifications are pretty clear, there is example code,
I am using a piece of self-modifying code for a college project. Here it
Okay, I have reached a sort of an impasse. In my open source project,
Before I invest the time in modifying the SubSonic 3 source, I figured I

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.