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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T19:28:05+00:00 2026-05-15T19:28:05+00:00

What are the differences between Expression trees and CodeDom? Which should I use for

  • 0

What are the differences between Expression trees and CodeDom?
Which should I use for which scenario?

  • 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-15T19:28:06+00:00Added an answer on May 15, 2026 at 7:28 pm

    Expression trees have a lot in common with (for example) an AST. It doesn’t map directly to code, but is very amenable to construction from algorithms. For example, if you are parsing a formula:

    ((a + 2) / b)
    

    that is:

    ParameterExpression a = ..., b = ...
    var body = Expression.Divide(
        Expression.Add(a, Expression.Constant(2)),
        b);
    var lambda = Expression.Lambda(body,a,b); // optionally with generics
    

    In fact, I have done exactly this, using a parser that build an object tree, with objects generating the complete expresion via a “visitor” implementation. In .NET 4.0, the richer expression-tree support makes it possible to support most scenarios, and compile it on demand.

    Another key use of expressions is that you can deconstruct them at runtime, so in your code you might have:

    Foo(x => x.SomeMethod(1, "abc"));
    

    and extract the SomeMethod method-info, 1 and "abc" etc.


    codedom maps to code. It is all about statements etc, very similar to how you would write regular code. The most common use of codedom is for code generation, as part of tooling. You can use it for dynamic compilation, but to be honest it is harder. I am not a fan. The nice feature is that a codedom tree might work for multiple languages.


    Another contender here should be DynamicMethod and/or ILGenerator. This doesn’t map to an AST (expression), and can’t be used to generate source-code (codedom), but allows full access to the MSIL tools. Of course, it also requires that you think in terms of stacks etc, but it is very efficient and effective for meta-programming.


    If ILGenerator is too hard-core, and codedom is a PITA, then another option is runtime generation of code as a string. Then pass that through CSharpCodeProvider to compile it. There are parts of the core runtime that do this (XmlSerializer IIRC).


    So to summarise:

    • meta-programming: ILGenerator or CSharpCodeProvider; also Expression in 4.0 (but this is quite limited in 3.5)
    • handling AST: Expression
    • parsing at runtime: Expression
    • code-generation in multiple languages: code-dom
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

What are the differences between preg_replace() and preg_filter() ? In which situations should I
What are the main differences between these WPF controls? And when I should use
I have a basic question about parsing expression trees. Is there a difference between
What is the difference between a lambda expression and a predicate in .NET?
Possible Duplicate: What is the difference between a function expression vs declaration in Javascript?
The differences between StringBuilder and StringBuffer in Java are well documented and have been
There are any differences between using SetValue with (for example) Canvas.LeftProperty and Margin Property?
Are there any differences between LEA $1000,A0 and MOVE #$1000,A0 to put an address
I know the differences between IBAction and IBOutlet, but I don't know when I
What are differences between Visibility.Collapsed and Visibility.Hidden in WPF?

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.