views:

40

answers:

2

Is there a trick to use static reflection with Visual Studio 2008 targeting .net framework 2.0 ?

+2  A: 

No, because so called "static reflection" requires expression trees, which are only available in .NET 3.5+.

Note that LinqBridge, a library which makes some Linq features available to .NET 2.0 code, doesn't implement expression trees

Thomas Levesque
+2  A: 

Actually, it isn't quite true that you need .NET 3.5 for this. What you need is the Expression classes; you can write these for 2.0 (I've done it for C# 3.0 targetting CF, which lacks Expression), but is isn't very easy, and I'd question the benefit.

If you value your sanity, I'd say stick with strings until you upgrade to 3.5. Sorry.

Marc Gravell
That's exactly what I was looking for: with LinqBridge (ExtensionAttribute) and your Expression source code I'm able to do things like this targeting .net 2.0:firstNameTextBox.Bind(person, p => p.FirstName);Thank you !
Catalin DICU
Wow... impressive ! It's the second time today that I'm proved wrong when I was pretty sure of my answer... but that's a good thing, I'm always glad to learn something new ;)
Thomas Levesque