What does Expression.Quote() do that Expression.Constant() can’t already do?

Short answer: The quote operator is an operator which induces closure semantics on its operand. Constants are just values. Quotes and constants have different meanings and therefore have different representations in an expression tree. Having the same representation for two very different things is extremely confusing and bug prone. Long answer: Consider the following: (int … Read more

Are Roslyn SyntaxNodes reused?

UPDATE: This question was the subject of my blog on June 8th, 2012. Thanks for the great question! Great question. We debated the issues you raise for a long, long time. We would like to have a data structure that has the following characteristics: Immutable. The form of a tree. Cheap access to parent nodes … Read more

Retrieving Property name from lambda expression

I recently did a very similar thing to make a type safe OnPropertyChanged method. Here’s a method that’ll return the PropertyInfo object for the expression. It throws an exception if the expression is not a property. public PropertyInfo GetPropertyInfo<TSource, TProperty>( TSource source, Expression<Func<TSource, TProperty>> propertyLambda) { Type type = typeof(TSource); MemberExpression member = propertyLambda.Body as … Read more

Why would you use Expression rather than Func?

When you want to treat lambda expressions as expression trees and look inside them instead of executing them. For example, LINQ to SQL gets the expression and converts it to the equivalent SQL statement and submits it to server (rather than executing the lambda). Conceptually, Expression<Func<T>> is completely different from Func<T>. Func<T> denotes a delegate … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)