Questions tagged [expression-trees]

Expression Trees are an abstract representation of code in a tree structure where each node of the tree represents a programming construct (conditional, assignment, method call, etc.)

2
votes
1answer
32 views

Evaluate an expression binary tree - Daily Coding Challenge

Here is my solution for the Daily Coding Challenge 50 Given an arithmetic expression in the form of a binary tree, write a function to evaluate it Example ...
6
votes
3answers
231 views

Simple object validator with a new API

Quite some time ago I have created the Simple object validator (see also self-answer). The more I used it the more I thougt its API could be better so I have heavily refactored it and would like to ...
2
votes
1answer
48 views

Populating dropdown lists, using SQL vs. using expression trees and reflection

I'm working with a large enterprise SQL Server database with dozens of tables that are used mainly as lookups to populate dropdown lists, etc. These tables all follow the convention of having (table)...
3
votes
0answers
22 views

Configure multiple application features by common criteria

My FeatureSerivce provides only basic APIs, so it is good in dealing with single features. Like I can configure only one feauture at a time: ...
2
votes
2answers
64 views

Creating keys/names from interfaces to avoid strings

There are many APIs that require some kind of a string key/name. I usually try to avoid using raw strings and prefer to use ...
1
vote
0answers
64 views

Extension “With” for immutable types

(My code is basically a rewrite of https://github.com/ababik/Remute so much of the credit goes there) The idea is to use lambda expression to provide a general With...
2
votes
0answers
47 views

Quiz for random boolean expressions

Inspired by the various quiz programs on this site, as well as Simon Tatham's puzzle collection, I thought I'd write a quiz that constructs its questions automatically and randomly. A typical session ...
5
votes
1answer
242 views

Adjusting business logic conveniently through JSON and expression trees

I need to evaluate some data. The rules how it should be done are changing frequently (it's an evolving model) so I don't want to rewrite my application each time such a change comes. I'd rather do it ...
4
votes
1answer
75 views

Dynamic setting names based on properties

In one of my frameworks that I use with many tools I have an ExpressionVisitor whose job is to resolve the exact property, it's declaring type and instance. I ...
1
vote
1answer
154 views

Expression tree in Haskell with support for differentiation

A simple binary expression tree in Haskell without operator precedence and without parentheses. Any comments would be much appreciated. ...
13
votes
3answers
409 views

Building unusual IComparer<T> from expressions

I've needed a couple of very special comparers recenty and didn't want to implement each one of them every time so I created a builder and a couple of supporting classes that do that for me. Example ...
8
votes
4answers
603 views

Selective updates to immutable types

There is a way in Scala to selectively change a field while making a copy of the immutable object: ...
5
votes
1answer
189 views

Inserting into a binary expression tree with GOTO

I'm working on a binary space partition tree. For the time being, the nodes are only inserted into the right. A node that has children will have 0 as data. Here are the insertion rules. If the ...
12
votes
3answers
727 views

Building DebuggerDisplay strings

The DebuggerDisplayAttribute is a very helpful feature. But creating those strings is an extremely tedious task. I wanted to make it a no-brainer so that I can ...
2
votes
0answers
95 views

Implementing the IQueryable counterpart method of the IEnumerable method?

I have created this method to simulate SQL's IN operator: ...
9
votes
6answers
4k views

Calculate fingerprint for an object

I need to store serialized objects in a database and I want to avoid duplicates. In order to be able to tell wheter an object is already stored, I have to compare them somehow. My idea was to ...
16
votes
6answers
7k views

Simple object validator

I wrote a simple validation tool that allows me to quickly define validation rules and check my data objects against them. I know there is this another tool called FluentValidation but... I'm not a ...
6
votes
4answers
375 views

Simple generic sequence generators

I've been improving some of my old sequence generators that worked with generics and lambdas in order to support binary operators for the specified T: ...
9
votes
5answers
430 views

Declarative type comparer

Writing comparers by either implementing the IEqualityComparer<T> or the IEquatable<T> interface is another boring ...
2
votes
1answer
164 views

Unit-test helper extensions for binary operators

This time I'd like you to review my unit-test helpers for binary operators. I wrote them because I'm often to lazy to test these operators because writing those tests is so boring. My little helpers ...
8
votes
1answer
2k views

GroupBy(params string[] fields)

Linq to Object GroupBy extension method allows grouping by projection: ...
5
votes
1answer
348 views

Extensions for setting members via expressions and reflection

I'd like to make the usage of my configuration framework easier so I created a few extensions that after getting a value from a source automatically assign it to a property or field. They should make ...
2
votes
0answers
77 views

Computer Algebra System that computes symbolic derivatives

I have a system that parses a mathematical expression String, creates a derivative expression tree, and reconstructs the derived expression into a new ...
4
votes
1answer
2k views

Generating variable names and getters from member expression

I have a JSON configuration file where the user is allowed to use inside strings certain placeholders {Type.Name} that later will be interpolated with the actual ...
5
votes
1answer
163 views

Calculating user efficiency on a time period with Linq

I have this expression: ...
4
votes
1answer
713 views

Specification pattern in EF part 2

This is a follow on to Part 1 In order to use my new Specifications within expression trees so I can use them in projections/navigation collections I had to write ...
8
votes
2answers
2k views

Specification pattern in EF part 1

I've been experimenting with different ways of reusing (and naming) the expressions I use in Entity Framework. I've tried static fields with Expressions and ...
7
votes
1answer
255 views

LINQ Provider: Supporting Projections

Up until recently, my LINQ-to-Sage provider didn't support projections, so the client code had to explicitly "transfer" to LINQ-to-Objects, like this: ...
3
votes
1answer
223 views

Validation extensions

I've been working on another timesaver because I really really don't like to type all those validation ifs and exceptions over an over again. What I came up with ...
4
votes
1answer
277 views

Binary expression tree node with two possible states

I am building out a binary expression tree and shown below is an implementation of the tree's node. The node can be either a leaf or non-leaf, with leaves having ...
2
votes
1answer
1k views

Building expression tree with multiple OrElse

I am creating a way for users to filter results based on start and end values. An example of this would be: ...
10
votes
1answer
203 views

Linq-to-Sage Implementation

Following-up on my last question where I wrapped the Sage API with a familiar IRepository interface, I decided to push the abstraction a step further, and... ...
12
votes
2answers
244 views

Something like a LINQ provider

Ok, before you ask: yes, I need to do this. Sort of. I'm wrapping a 3rd-party API for data access, and I can't use an ORM, so I'm implementing this kind of thing: ...
7
votes
1answer
241 views

NullGuard for throwing more informative exceptions

This small utility class is my solution for a more convenient way for checking against null. I also wanted to have more informative NullReferenceExceptions but I ...
0
votes
1answer
391 views

Refactor Linq Expression [closed]

Is there any way I can refactor this expression tree? ...
8
votes
3answers
21k views

Generic advanced Delegate.CreateDelegate using expression trees

As far as I know the standard Delegate.CreateDelegate() which allows to create a delegate by using reflection, doesn't allow doing something as follows when the ...