In a couple past blog posts, we talked about how as of build 501, syntax languages implemented the service locator design pattern. The Syntax languages to be service locators topic discussed the generics-based implementation of the service locator pattern and how we also added extension methods so that the most commonly used “services” could easily be registered and retrieved.
We had implemented these extension methods in build 501 using a trick (since SyntaxEditor targets .NET 3.0) but later found a problem with that trick. Thus build 502 fixes the problem introduced in build 501.
The trick to get extension methods to work in .NET 3.0 or earlier
The problem with extension methods is that they technically require your projects to target .NET 3.5 to get them to work. However someone discovered that you can define an ExtensionAttribute in the same namespace as the .NET 3.5 one and put that in your .NET 3.0 or earlier projects to get extension methods working in VS 2008 there too.
It’s a really neat trick until you encounter the problem scenario.
The problem scenario
The problem scenario occurs in Visual Basic projects only that reference an .NET 3.5 or later assembly which uses “real” extension methods. In that case, the VB project will throw an error on compile and fail to compile.
This blog post talks about the issue in more detail.
The solution implemented in build 502
Since we still target .NET 3.0, the only real option for us was to make the extension methods open source. So in build 502 we have moved the source code for them to the Sample Browser, where you may copy it to your own projects to use it if you’d like.
In the future, when we eventually change the product to target .NET 3.5 or later, we’ll move the extension method code back into the SyntaxEditor assembly. We didn’t want to make that platform target change yet though.
Build 502 is live right now and ready for download. It also includes several tweaks and bug fixes to other products that we’ve found since the release of build 501.