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

Ask A Question

Stats

  • Questions 495k
  • Answers 495k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer You probably use objects without even realizing it. If you're… May 16, 2026 at 11:21 am
  • Editorial Team
    Editorial Team added an answer As written, I believe you have an error. You aren't… May 16, 2026 at 11:21 am
  • Editorial Team
    Editorial Team added an answer Certainly, look at this example: var pattern = @"^\D*(\d+)$"; var… May 16, 2026 at 11:21 am

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Related Questions

What are the differences between System.Dynamic.ExpandoObject , System.Dynamic.DynamicObject and dynamic ? In which situations
I was thinking about the difference between Expression<Func<>> and Func<> , and wondered if
Iam using one Jquery Library which takes the Regular expression in json format in
What are the differences between YAML and JSON, specifically considering the following things? Performance
Are there differences between /\((.*)\)/ and /\(([^\)]*)\)/ ? In particular, would the second regular
The only differences between randrange and randint that I know of are that with
What are the differences between 32 and 64-bit .NET (4) applications? Often 32-bit applications
Can anybody provide a brief explanation of the differences between mongrel and mongrel cluster?
I'm working on a Silverlight project and I'm trying to understand the differences between
im trying to fix a bad website, there was alot of differences between chrome,

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.