2,115 questions
0
votes
1
answer
77
views
Chain MethodCallExpression with Expression
I am trying to have MethodCallExpression compiled with a lambda expression. Basically i want a method to be called everytime the lambda expression is invoked.
I am not sure i'm even on the right path ...
0
votes
1
answer
65
views
Moq fully generic Setup with class proxy attempt throws `Late bound operations cannot be performed`
PROBLEM TO SOLVE
I'm trying to create a mock of interface ISomeService using Moq library which will wrap its real implementation SomeService.
Right now I'm doing this manually like this:
var instance =...
3
votes
1
answer
61
views
When trying to convert a method to expression tree, got an error 'System.Void' cannot be used for return type ''
I'm trying to convert a method to an expression tree for a test, but I got an error
Exception thrown: 'System.ArgumentException' in System.Linq.Expressions.dll Expression of type 'System.Void' cannot ...
0
votes
0
answers
66
views
How can I create a parameter expression to be used in a func<EndpointAddress> expression with a predefined value?
I am trying to build a Dictionary(Of Type, Func(Of ServiceModel.EndpointAddress)). The func represents a method which takes in a single string parameter which is the service url and returns a ...
2
votes
2
answers
87
views
Dynamically created event handler that writes ito a `ref` parameter
I want to subscribe to any event existing on a given object, where I don't know the type in advance. I'm generatig event handler at run-time using System.Linq.Expressions.Expression.
The code I have (...
0
votes
2
answers
116
views
Dynamically Build LINQ Expressions - ToLower and Contains at the same time
I struggle with adding ToLower() to the Contains LINQ Expressions:
Here is the code of mine with dynamic LINQ Expressions (Contains):
private static Expression GetExpressionCase<T>(...
1
vote
1
answer
77
views
NHibernate - Problem with creating a custom Linq extension
I have such query in NH Linq:
var query = _session
.Query<Revision>()
.Join(
_session.Query<Document>(),
rev => rev.Document,
doc => doc,
(rev,...
1
vote
2
answers
130
views
Compiled lambda expression leading to new delegate allocations, whereas non-expression version does not
This compiled expression tree...
var param = Expression.Parameter(typeof(int));
var innerParam = Expression.Parameter(typeof(Action<int>));
var inner = Expression.Lambda(innerParam.Type, ...
3
votes
2
answers
142
views
Expression trees - invoke lambda during loop leads to variable leaking
I have found little issue with expression trees and would like to know whether such is a bug or a feature. I have this code. The first function assigns one to a variable and returns it.
static class ...
0
votes
0
answers
76
views
Creating a Lambda for LINQ from code gives error message "Parameter could not be translated"
I am attempting to build a lambda from data.
The module entity has an AlgNo property of type string.
I am trying to get a simple sample code to run before attempting the more advanced case.
Consider ...
0
votes
0
answers
65
views
Expression tree - how to check if element of a list fulfills specific conditions?
I'm using an
Expression<Func<T, object?>> DatabaseProjection which defines what values I want to extract from T. In specific case, I will get a list of objects (string or int):
...
0
votes
1
answer
84
views
Expression.Call on array with a custom function
I have a list of items, I want ,via expression, to filter out the items using my own custom function.
Something like this
return Items.Where(Foo)
private static bool Foo(Item item) { item.Name.Equals(&...
0
votes
0
answers
43
views
Create expression trees using generic arguments which involves nested properties [duplicate]
I am trying to create a dynamic query generator, using generic arguments.
For example:
Expression<Func<T, bool>> CreateExpression<T>(
ParameterExpression parameter,
List<...
1
vote
1
answer
66
views
Accessing x levels of n-ary tree to manipulate a node and add child node with recursion
I have a problem I'm trying to solve where I can take in a variety of expression of different lengths and complexities and insert them as nodes into an n-ary (or non-binary) tree.
I need to pinpoint ...
4
votes
3
answers
227
views
Is there no way for Csharp to write a truly static λ expression?
Language : C#
.Net Version : 8.0
IDE : VS2020 / VSCode
OS : Windows11
Is there no way for Csharp to write a truly static λ expression?
I studied currying today and wrote a ...