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...
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...
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(...
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...
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...
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 ...
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...
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, ...
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...
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...
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 ...
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...
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...
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...
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...
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);
};
}
...
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...
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...