expression-trees

Accessing elements of types with indexers using expression trees

好久不见. 提交于 2019-12-11 13:13:55
问题 Suppose I have a type like this: class Context { SomeType[] Items { get; set; } } I want to be able to access specific Items elements using expression trees. Suppose I need an element at index 0 . I can do it like below, where everything works as expected: var type = typeof (Context); var param = Expression.Parameter(typeof (object)); var ctxExpr= Expression.Convert(param, context); var proInfo = type.GetProperty("Items"); Expression.ArrayIndex(Expression.Property(ctxExpr, proInfo),

Composing expression trees for composite DTO

血红的双手。 提交于 2019-12-11 13:12:20
问题 Let's say I have the 3 followings DTOs public class Mailing { public long Id { get; set; } //... public long IdSender { get; set; } public Sender Sender { get; set; } public long IdTemplate { get; set; } public Template Template { get; set; } } public class Sender { public long Id { get; set; } public string Email { get; set; } //... } public class Template { public long Id { get; set; } public string Name { get; set; } //... } And I have 3 expression trees to manage DAO-to-DTO conversion :

Adding Expression argument as property in LINQ to Entities

不羁的心 提交于 2019-12-11 13:07:34
问题 Using EF6, how would I bind a given Expression<Func<Row, string>> argument to an existing select expression, without having to rewrite every property binding using expression trees? public IEnumerable<RowModel> GetRowModels(Expression<Func<Row, string>> textExpr) { return from row in MyDatabaseContext.MyTable select new RowModel { RowID = row.ID, CreatedDate = row.CreatedDate, AnotherProperty = row.AnotherProperty, Text = textExpr, // how do I bind this expression? Value = row.OtherStuff

Expression Tree ToString() method generates strange string WHY?

回眸只為那壹抹淺笑 提交于 2019-12-11 12:27:25
问题 I need string conversion of an Expression Tree so I create an Expression Tree and use ToString method like this var exp = ((Expression<Func<UserDetailInfo, bool>>) (x => x.OperationID == operationId)).ToString(); but result is strange x => (x.OperationID == value(TCS.Proxy.PermissionProxy+<>c__DisplayClass5).operationId) TCS.Proxy.PermissionProxy is my class in WCF proxy project !!! (I send expression from client to proxy) but when I create this Expression myself everything is good var entity

Haskell creating new data

生来就可爱ヽ(ⅴ<●) 提交于 2019-12-11 12:06:12
问题 {- P A R T 2 : Implementation of a parser for Łukasiewicz expressions --TODO Define the type LExpTree, using the constructors L, V, N, Q, S, K, A, O, E, I L for Lukasiewicz literals (i.e. C, I or U) V for Variables (string) N for a node representing the prefix neg Q for a node representing the prefix pos S for a node representing the prefix cer K for a node representing the prefix unk A for a node representing the infix And O for a node representing the infix Or E for a node representing the

Convert expression tree types

牧云@^-^@ 提交于 2019-12-11 10:46:22
问题 I've searched high an low of SO to find a solution for my problem. I've found several answers for when it comes to simple expressions like var exp1 Expression<Func<T, bool>> x => x.Name == "MyName" But I'm having trouble when the expressions are like: var exp1 Expression<Func<T, bool>> x => x.Category.Name == "Coupe" For the simple ones, I am able to convert any expression from one type (T) to another (TT), I need to do it also in the other cases, more complex... Anyone who can help with some

c# linq MethodCallExpression for Max(DataRow) used for .GroupedBy().Select()

早过忘川 提交于 2019-12-11 08:54:46
问题 The question hereby refers to my previous question here The Sum() expression advised by @xanatos worked perfectly. I tried also Max() expression for the field of the type double and faced no issue. As the next step I decided to add the DateTime field and calculate Max() for it. I modified the GroupSum class as follows: private class GroupSum : GroupKey { public Double AggN0 { get; set; } public DateTime AggD0 { get; set; } } And programmed the function: private static Func<IGrouping<GroupKey,

What is the simplest way to parse an expression and retrieve a parse tree?

吃可爱长大的小学妹 提交于 2019-12-11 08:31:33
问题 I just want to parse simple expressions like - IIF(FVAL(PFC) = TRUE, (IIF((ORGVAL(BAS, "2012/12/31") + ORGVAL(DA)) < 6500, (FVAL(BAS) + FVAL(DA)) * 12%, 780)), 0)` After parsing this I should be able to know what functions contains what parameters. |-FVAL |-PFC |-ORGVAL |-BAS |-"2012/12/31" I'm stuck with .Net Framework 2.0, so no Linq or lambda expression goodies for me. Also I want to include the code in my custom library and not just reference it. Can anyone point me to some good library

Is it possible to convert a lambda expression of some return type to its equivalent expression of a more specific type?

青春壹個敷衍的年華 提交于 2019-12-11 08:22:04
问题 public class Entity { public int A { get; set; } public string B { get; set; } } Expression<Func<Entity,object>> expr = x => x.A; Expression<Func<Entity,int>> exprAtRuntime = x => x.A; Expression<Func<Entity,object>> expr2 = x => x.B; Expression<Func<Entity,string>> expr2AtRuntime = x => x.B; How can I take expr and convert it to the type of expr2 at runtime? Likewise, I need to do the same for property B. I need to accept a params array of type Expression<Func<Entity,object>> which

Trouble implementing generic OrderBy solution

一曲冷凌霜 提交于 2019-12-11 06:59:46
问题 I have a method that takes IQueryable<T> and I want to implement OrderBy generically inside it. Ideally by passing in c => c.SomeProperty in as a parameter but I can't figure out how to get the generics working on that so I've tried it with a string. However I am getting the error: Incorrect number of parameters supplied for lambda declaration This is what I tried (using the string method) var sortSelectorParameter = Expression.Parameter(typeof(T), "c"); var sortSelector = Expression