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.)

Filter by
Sorted by
Tagged with
9
votes
2answers
239 views

Immutable builder and updater

There aren't enough questions about creating immutable objects... so why not try it again with another approach. This time, it's a builder that maps properties to constructor parameters. Properties ...
3
votes
1answer
39 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
285 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
53 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
28 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
70 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
71 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...
3
votes
0answers
63 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
329 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
79 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
169 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. ...
14
votes
3answers
420 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
648 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
198 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
787 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
101 views

Implementing the IQueryable counterpart method of the IEnumerable method?

I have created this method to simulate SQL's IN operator: ...
10
votes
6answers
5k 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 ...
17
votes
6answers
9k 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
421 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
471 views

Declarative type comparer

Writing comparers by either implementing the IEqualityComparer<T> or the IEquatable<T> interface is another boring ...
2
votes
1answer
222 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
374 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
78 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 ...
5
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 ...
3
votes
1answer
2k views

Parsing and evaluating cron expression

I wasn't happy with my last attempt to parse a cron expression so I simplified it and now I use regex instead. I'd like you to take a look at this solution whether I'm doing something terribly wrong. ...
5
votes
1answer
165 views

Calculating user efficiency on a time period with Linq

I have this expression: ...
4
votes
1answer
762 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 ...
9
votes
2answers
3k 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
260 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
237 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
292 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 ...
6
votes
1answer
5k views

Tracking which entity properties have changed

There are a number of topics pertaining to entity change tracking. All the ones I've seen involve either 1) notifying when a property has changed or 2) merely determining whether or not an entity is ...
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
205 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
256 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
260 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 ...
-1
votes
1answer
425 views

Refactor Linq Expression [closed]

Is there any way I can refactor this expression tree? ...
9
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 ...