One feature of the CLR that is not available in C# or VB.NET are module initializers (or module constructors). A module initializer is simply a global function which is named .cctor and marked with the attributes SpecialName and RTSpecialName. It is run when a module (each .NET assembly is comprised of one or more modules, typically just one) is loaded for the first time, and is guaranteed to run before any other code in the module runs, before any type initializers, static constructors or any other initialization code. I wanted to use this feature for a project I was doing but was unable to use it directly in C# so I created my own solution. (more…)
4 Feb 2010: I’m no longer working on this addin and cannot provide support for failed installations. I gave some information about possible causes for failed installations in this comment, you can see if that helps, or discuss with other users in the comments. There are unlikely to ever be new versions of this addin published by me, but Boris Sevo has forked the project and has a version with a newer zencoding library at http://zencoding.codeplex.com/. So go there for updates
The original blog post about the architecture of the addin is now completely out of date as 90% of the addin is now written in IronPython with just a tiny shim layer of C# to instantiate the IronPython classes. I’ll probably write a blog post about that architecture seperately (or generally about how to write addins for VS in IronPython). Those interested in the architecture can download the source and look at it.
A nice tutorial with screenshots on how to setup the keyboard mappings and use the addin has just been posted at http://www.netsi.dk/wordpress/index.php/2009/12/02/zen-coding-a-very-fast-way-of-generating-html-elements-in-your-editor/ so go there for your setup instructions. And there is now a dedicated rss feed for updates at http://tech.einaregilsson.com/zcupdates.aspx so subscribe to that to be notified of new versions. Eventually I’ll put an update check in the addin itself.
ZenCoding.VisualStudio v1.1.0.333
It’s been a while since I’ve written anything here, I’ve been working on my master project like crazy, have a 6 month old baby and so haven’t had much time for programming pet projects. Tonight I spent a half hour making perhaps the most useless application I’ll ever make. It’s based on the single-serving website http://instantrimshot.com which only has one huge red button, if you press it a rimshot sound is played. I thought it might be fun to have that available as a keyboard shortcut in windows, and then I started wondering how it could be done in C#.
Lately I have been doing some COM automation stuff on Windows. I’ve been using JScript (Microsoft’s JavaScript implementation) since that’s available on all Windows machines, and the other option, VBScript, is horrible. Normally I would use Python and the win32com package, but I needed to make some scripts that could work on any box without installing Python first. JScript is a pretty nice language, but it doesn’t come with a REPL built in, which is very handy when you’re doing experimental stuff (REPL = Read-Execute-Print-Loop). Now, writing your own REPL in a dynamic language with an eval statement is pretty easy, so I did just that. It took about 30 lines, of which about 10 are just about printing evaluated expressions nicely. (more…)
I was watching a movie on my computer the other day and I had gotten the subtitles for it off the internet, I think from http://opensubtitles.com or something like that. The only problem was that they were a bit out of sync with the picture, about 2 seconds too late. Using a good media player, such as VLC you can add an offset to the subtitles every time you watch the movie but I figured I could probably whip up a small script to do it for me so I could just do it once and then have the subtitles correct every time I watched the movie. (more…)