expression trees linq get value of a parameter?

expression trees linq get value of a parameter?

AddOptional<tblObject>(x =>x.Title, objectToSend.SupplementaryData);  private static void AddOptional<TType>(Expression<Func<TType,string>> expr, Dictionary<string, string> dictionary) {     string propertyName;     string propertyValue;      Expression expression = (Expression)expr;     while (expression.NodeType == ExpressionType.Lambda)     {         expression = ((LambdaExpression)expression).Body;     } } 

In Above code i would like to get actual value of property title, not ony propert name , is it possible ?

LINQ exclusion


Linq - Row not found or changed
private static void Main(string[] args) {     CompileAndGetValue<tblObject>(x => x.Title, new tblObject() { Title =  "test" }); }  private static void CompileAndGetValue<TType>(     Expression<Func<TType, string>> expr,     TType obj) {     // you can still get name here      Func<TType, string> func = expr.Compile();     string propretyValue = func(obj);     Console.WriteLine(propretyValue); } 
However, you must be aware that this can be quite slow.

Your Favorite LINQ-to-Objects Queries [closed]
You should measure how it performs in your case..
How to move from LINQ to SQL to “LINQ to WCF”?
If you don't like to pass your object:.
LINQ to Entities and creating a new instance of an entity
    private static void Main(string[] args)     {         var yourObject = new tblObject {Title = "test"};         CompileAndGetValue(() => yourObject.Title);     }       private static void CompileAndGetValue(         Expression<Func<string>> expr)     {         // you can still get name here          var func = expr.Compile();         string propretyValue = func();         Console.WriteLine(propretyValue);     } 

Linq-to-sql One-To-Many with a max

85 out of 100 based on 85 user ratings 235 reviews