A Journey Into Expressions
I have been a little obsessed with LINQ and Func<T,TResult> of late and finally managed to find some time to do a little bit of exploration into the System.Linq.Expressions namespace.
I have published an article over at codeproject (http://www.codeproject.com/KB/linq/Expressions.aspx) which tells you all about how to create the following
lamda expression : (x) => x.Length > 1 , entirely in code using the System.Linq.Expressions namespace.
In case you are curious this is what this expression looks like when working with the System.Linq.Expressions namespace:
1: ConstantExpression constLength = Expression.Constant(1);
2:
3: ParameterExpression stringParameter =
4: Expression.Parameter(typeof(String), "s");
5:
6: MemberExpression stringMember =
7: LambdaExpression.PropertyOrField(stringParameter, "Length");
8:
9:
10: Expression<Func<String, Boolean>> bindLambda =
11: Expression.Lambda<Func<String, Boolean>>
12: (
13: Expression.GreaterThan(
14: stringMember,
15: constLength),
16: stringParameter
17: );
18:
19:
20: foreach (String bindingString in
21: bindings.Where(bindLambda.Compile()))
22: {
23: .....
24: }
In the article I obvisouly talk in a lot more detail, so if you want to know more, just have a look at the full article http://www.codeproject.com/KB/linq/Expressions.aspx


























2008 November 03 - Links for today « My (almost) Daily Links said
am November 3 2008 @ 9:28 am
[...] Sacha Barber goes in-depth with A Journey Into Expressions [...]
Yogesh said
am November 7 2008 @ 5:36 pm
The comment parsed removed the code I posted as XAML example. I am replacing the opening and closing tags with their XML counterparts:
<toolkit:DataGridTextColumn Header=”Alias” Width=”*”
Binding=”{Binding GroupAlias}” IsReadOnly=”True” />
sacha said
am November 8 2008 @ 3:13 pm
Yogesh I don’t know what type of thing a <toolkit…./> object is, but if it is anything like the Grid in WPF which uses * notation, you should do something like
Width = new GridLength(1,GridUnitType.Star);
Hope that helps
Yogesh said
am November 9 2008 @ 1:51 pm
Wow man… Thanks a lot. You rock.
PS: It is the WPF toolkit which is just released. So in my case, it is Width = new DataGridLength(1, DataGridLengthUnitType.Star). Thanks again man.
sacha said
am November 9 2008 @ 2:17 pm
Whats in the Toolkit, haven’t seen it yet. Is that the DataGrid etc etc
Yogesh said
am November 9 2008 @ 3:03 pm
Yes. Contains these controls…
1. DataGrid
2. Calendar
3. Date time picker
4. Ribbon control
I found the library to be good. Although there are some errors I faced, and no one replied on the discussion threads, but still, I think this is real good stuff. Just adding a Today button in the Calendar has such work cut in.
I think you should check it out too.
sacha said
am November 9 2008 @ 4:51 pm
Thanks for letting me know man, I have actually seen the grid before. We use Infragistics grid at work. GRRR
Yogesh said
am November 9 2008 @ 7:59 pm
I too was using the Xceed free version, but I gave it up for this grid as the Xceed free version is almost same as this one. I am too short of money to buy a commercial grid. Although it contains a lot of errors as of now, I think that this grid might eventually match all the goodies offered by commercial grids.
BTW, both Infragistics’s and Xceed’s grid are really powerful.
sacha said
am November 9 2008 @ 8:56 pm
Yeah, truth be known I am not that keen on Infragistics grids internal behvaiour, but it looks good.