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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T13:54:39+00:00 2026-06-12T13:54:39+00:00

I have something like this in LinqPad void Main() { var t1 = DateTimeOffset.Parse(10/1/2012);

  • 0

I have something like this in LinqPad

void Main()
{
    var t1 = DateTimeOffset.Parse("10/1/2012");

    int? n1 = 1;

    Expression<Func<Sample,bool>> x1 = ud => 
        (ud.Date == t1 && ud.Number == n1);

    x1.ToString().Dump();
}

class Sample
{
    public int? Number{set;get;}
    public DateTimeOffset Date{set;get;}
}

it outputs

ud => ((ud.Date == value(UserQuery+<>c_DisplayClass0).t1) AndAlso
(ud.Number == value(UserQuery+<>c
_DisplayClass0).n1))

is there any possible way to keep the variables but have it output something like this:

ud => ((ud.Date == Parse(“10/1/2012”)) AndAlso (ud.Number ==
Convert(1)))

  • 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-12T13:54:40+00:00Added an answer on June 12, 2026 at 1:54 pm

    Here we go; output first:

    ud => ((ud.Date == 10/01/2012 00:00:00 +00:00) AndAlso (ud.Number == 1))
    

    This will never output Parse(...), because your expression does not contain a parse: you have already evaluated that by the time you put it into a lambda.

    Note also that this handles one level of captured variable. For more complex (nested) capture contexts, you’ll have to recursively fetch the values from the capture classes:

    using System;
    using System.Linq.Expressions;
    using System.Reflection;
    using System.Runtime.CompilerServices;
    static class Program
    {
        static void Main()
        {
            var t1 = DateTimeOffset.Parse("10/1/2012");
    
            int? n1 = 1;
    
            Expression<Func<Sample, bool>> x1 = ud =>
                (ud.Date == t1 && ud.Number == n1);
    
            var sanitized = (Expression<Func<Sample, bool>>)
                new Literalizer().Visit(x1);
    
            Console.WriteLine(sanitized.ToString());
        }
    }
    
    class Literalizer : ExpressionVisitor
    {
        protected override Expression VisitMember(MemberExpression node)
        {
            if(node.Member.DeclaringType.IsDefined(typeof(CompilerGeneratedAttribute), false)
                && node.Expression.NodeType == ExpressionType.Constant)
            {
                object target = ((ConstantExpression)node.Expression).Value, value;
                switch (node.Member.MemberType)
                {
                    case MemberTypes.Property:
                        value = ((PropertyInfo)node.Member).GetValue(target, null);
                        break;
                    case MemberTypes.Field:
                        value = ((FieldInfo)node.Member).GetValue(target);
                        break;
                    default:
                        value = target = null;
                        break;
                }
                if (target != null) return Expression.Constant(value, node.Type);
            }
            return base.VisitMember(node);
        }
    }
    
    class Sample
    {
        public int? Number{set;get;}
        public DateTimeOffset Date{set;get;}
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have something like this: typedef int AnotherType; template <typename T> Func( T Value
I have something like this : code.js var params = { option1 : encodeURIComponent(text\n
I have something like this: create table account ( id int identity(1,1) primary key,
I have something like this... void f(dclass b); class dclass { dclass(string s); };
I have something like this: var users = []; Then I use this to
I have something like this: Main view: @model AuthorViewModel @using (Html.BeginForm(Action, Controller, FormMethod.Post, new
I have something like this: Scanner in=new Scanner(System.in); int rounds = 0; while (rounds
i have something like this var emp = db.Employees.toList(); in my employees table i
I have something like this: var Something = function(){ this.render = function(){}; $(window).resize(function(){ this.render();
I have something like this: private void DoSomething() { System.Console.WriteLine(Creating Foo); Foo result =

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.