The method
GetSingle
is a method of some class that you did not show, unfortunately. You also did not provide other declarations needed to compile this code. So, we can only infer that this is a class with at least one generic parameter —
T
.
So, this should be a class with something like this:
class ExpressionTest<T> {
public T GetSingle(Expression<Func<T, bool>> whereCondition) {
return this.ObjectSet.Where(whereCondition).FirstOrDefault<T>();
}
}
Now, at the moment of generic instantiation we need to substitute a real complete type for
T
. For the type int, it will look like this:
ExpressionTest<int> test = new ExpressionTest<int>();
To call
GetSingle
we need to build some expression based on the function which accepts one
int
parameter and returns
bool
:
using System;
using System.Linq.Expressions;
var test = new ExpressionTest<int>();
Expression<Func<int, bool>> expr = i => i < 5;
test.GetSingle(expr);
To understand this, you first need to understand
generics more thoroughly.
Second step is understanding of
lambda expressions, see
http://en.wikipedia.org/wiki/Lambda_(programming)[
^]. For lambda in .NET, see
http://msdn.microsoft.com/en-us/library/bb397687.aspx[
^],
http://msdn.microsoft.com/en-us/magazine/cc163362.aspx[
^].
Expressions in
System.Linq.Expressions
is much more advanced topic.
See
http://msdn.microsoft.com/en-us/library/system.linq.expressions.expression.aspx[
^],
http://msdn.microsoft.com/en-us/library/system.linq.expressions.aspx[
^].
Read introduction:
http://msdn.microsoft.com/en-us/library/bb397951.aspx[
^].
To give an what is it all about, I can give just one hint: Expression trees, in particular, is the base mechanism which can help to create a Computer Algebra System (CAS) for symbolic mathematical calculation in .NET, see
http://en.wikipedia.org/wiki/Computer_Algebra_System[
^].
—SA