zzz projects Expression Tree Tutorial
Getting Started Documentation Knowledge Base
  • Getting Started
  • Documentation
  • Knowledge Base

Expression Tree Tutorial - Knowledge Base (KB)

21 results for: in tag: dynamic

How to create an Expression<Func<dynamic, dynamic>> - Or is it a bug?

During my work with expression trees for a few days now, I came across something that I find difficult to understand; hopefully someone will be able so shed some light here....If you code ...Expression<Func<dynamic, dynamic>> expr1 = x => 2 * x;... the co...
.net-4.0 c# dynamic expression-trees lambda
asked by d..

C# 4 "dynamic" in expression trees

I'm trying to figure out how to put all the pieces together, and would appreciate a concrete source code sample for a simple case to start with....Consider the following C# code:...Func<int, int, int> f = (x, y) => x + y; ...I can produce an equivalent fu...
c# c#-4.0 dynamic expression-trees
asked by Pavel Minaev

Dynamic MemberExpression

I am wanting to create a MemberExpression knowing only the field name; eg:...public static Expression<Func<TModel, T>> GenerateMemberExpression<TModel, T>(string fieldName) { PropertyInfo fieldPropertyInfo; fieldPropertyInfo = typeof(...
c# dynamic expression-trees linq
asked by johnnyboy

Expression.Call and Count

I'm looking for a way to do following dynamically:...var q = context.Subscription .Include("Client") .Include("Invoices") Where(s=>s.Client.Invoices.Count(i=>i.InvoiceID == SomeInt) > 0); ...I would like to bu...
.net c# dynamic expression-trees linq
asked by Max

C# linq - Change the selected field at runtime

I have an object Orders (Order, Product, Cost, Price, Client, Day). I am retrieving a lot of records from the database and to facilitate filtering, I need to pouplate DropDownLists with the distinct values retrieved so the user can select only specific da...
c# dynamic expression-trees linq
asked by yipiha

Creating delegates dynamically with parameter names

Hi I'm trying to create a function that dynamically creates a delegate with the same return value and the same parameters as a MethodInfo it receives as parameter and also and this is very important the same parameter names!...What I did so far is create ...
c# delegates dynamic expression-trees parameters
asked by Uchiha Madara

ParameterExpression of type 'System.Int32' cannot be used for delegate parameter of type 'System.String'

I'm creating a general setter using expression tree and here is my code...public Expression<Action<T,string>> GetAction<T>(string fieldName) { ParameterExpression targetExpr = Expression.Parameter(typeof(T), "Target"); MemberExpression fieldExpr...
c# delegates dynamic expression-trees generics
asked by kans

Getting PropertyInfo Name and Value

I have seen various ways of doing this including reflection, component model type descriptors, expression trees, and aspects, BUT I'm still not sure whether the code below achieves all of the following objectives using .Net 4.0 or higher:...Be type safe, ...
c# dynamic expression-trees reflection typedescriptor
asked by Berryl

Why does string concatenation with the + operator work with dynamic types in C#?

I recently saw an example where the following was demonstrated to work:...T Add<T>(dynamic a, dynamic b) { return a + b; } Add<string>("hello", "world"); // Returns "helloworld" ...However, if I were to attempt to use expressions to create a "generi...
c# dynamic dynamic-language-runtime expression-trees string
asked by Matt H

Expression to create an instance with object initializer

Is there any way to create an instance of an object with object initializer with an Expression Tree? I mean create an Expression Tree to build this lambda:...// my class public class MyObject { public bool DisplayValue { get; set; } } // my lambda: v...
c# dynamic expression expression-trees lambda
asked by agent47

How to instantiate and initialize a dynamic object in expression tree?

When working with ...IQuerayble<TItem>... we can call ...Select... like this:...query.Select( item => new { A=item.Prop1, B=item.Prop2}); ...And ...Select... method expects ...Expression<Func<TItem,TResult>>...I need to use ...ExpandoObject... instead of ...
.net c# dynamic expression-trees iqueryable
asked by Pavel Voronin

Getting parameters of Func<T> variable

I have a rather complicated issue. I am trying to get a unique key from a method and its formal and actual parameters. The goal of the method, is to take a method call, and return a unique key based on 1) The name of the class and method and 2) The name a...
c# dynamic expression-trees func lambda
asked by Erik A. Brandstadmoen

Compiler Error : An expression tree may not contain a dynamic operation

Consider the following code, which wraps ...(rather than using inheritance for specific reasons)... an instance of ...Dictionary<string, T>... and implements ...IEnumerable... and ...IQueryable... so that it can be used with linq queries:...public class L...
c# compiler-errors dynamic expression-trees linq
asked by Matthew Layton

Expression Trees with dynamic parameter

I want to convert this:...Func<dynamic, object> myFunc = t => return t.Name + " " + t.Surname; ...Into an Expression Tree....What I have came up with, is this:...ParameterExpression target = ExpressionParameter(typeof(dynamic), "target"); ParameterExpress...
.net c# c#-4.0 dynamic expression-trees
asked by Matias Cicero

Creating linq expression trees for dynamic objects

I am trying to build an expression tree dynamically for sorting. The sorting will happen at the action filter of my web api. So the type of object will be unknown until runtime....Here's the overview: ...At the action filter level:...IEnumerable<object> m...
c# dynamic expression-trees lambda linq
asked by Newbee

Compiling statement collection to an action

So lets say I want to return an action like so ......public Action<T1, T2> BuildActionFrom(object[] stuff) { BinaryExpression[] expressions = BuildExpressions(stuff); return (x,y) => { foreach(var ex in expressions) ex(x,y); }; } ...
c# dynamic expression-trees
asked by War

Generating Action<T> with Expressions as strings

I'm trying to figure out how to generate an Action from a collection of strings the represent the actions "statement" lines ......using System.Linq.Dynamic; Action<T> BuildAction<T>(T sourceObject, T destinationObject) where T : BaseThing { var sourc...
c# dynamic expression-trees
asked by War

C# LINQ - selecting a dynamic object based on properties defined at runtime

I've been trying to create an expression which can project a strongly typed EF Core entity into a dynamic object containing a list which are defined at runtime using a REST API call....This is what I have so far:...Expression<Func<Message, dynamic>> Dynam...
c# dynamic entity-framework-core expression-trees linq
asked by Stu Ratcliffe

Building dynamic lambda expressions

I know how to build a simple lambda like ...x => x > 5...:...int[] nbs = new[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 }; IEnumerable<int> result1 = nbs.Where(x => x > 5); ParameterExpression parameter = Expression.Parameter(typeof(int), "x"); Consta...
dynamic expression expression-trees lambda tree
asked by Andy Rehn

Building dynamic lambda expression

I know how to build a simple lambda like ...x => x > 5...:...int[] nbs = new[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 }; IEnumerable<int> result1 = nbs.Where(x => x > 5); ParameterExpression parameter = Expression.Parameter(typeof(int), "x"); Consta...
dynamic expression expression-trees lambda tree
asked by Andy Rehn

Page 1 of 2
  • 1
  • 2
  • ยป

Prime Library

Performance

  • Entity Framework Extensions
  • Entity Framework Classic
  • Bulk Operations
  • Dapper Plus

Expression Evaluator

  • C# Eval Expression
  • SQL Eval Function
More Projects...