One for the programmers. (If you’re not one, look away now.)
Whenever I work on a nontrivial C# program, I usually end up writing the extension method shown at the bottom of this post. It lets me provide informative error messages when an exception bubbles up to the user, and promotes good error-handling generally. This is me sharing it with you, so you can enjoy it too.
Given an Exception, possibly containing inner exceptions, ‘ToFriendlyString()’ produces an ‘explanation’ from the chain of Exception.Messages: “This failed, because that failed, because the other failed.” Continue reading
I published a post a few months ago about a project of mine,
Dysphoria.Net.UrlRouting which aimed to bring strong typing to MVC4 ‘routes’.
If these words mean nothing to you, do not feel embarrassed (except if you’re a .NET web programmer, in which case, do feel embarrassed, and go read up on MVC post haste).
In the meantime I’ve excitingly a) used it for real in
one production project two commercial, production projects, b) filled in some missing gaps, and c) improved the syntax a little. I’ve also d) published it as a NuGet package.
It’s reached the point where I wouldn’t work on an MVC project without it. I’d very much like if Microsoft took a wee look and added it, or added something similar, into MVC.
You can install it from NuGet. The package is called Dysphoria.Net.UrlRouting.
There’s now a webpage for it, which includes a bit of a tutorial.
You can grab the source off of github.
I should probably think of a catchy name for it. ‘STIR’? (Strongly Typed urI Routing?) ‘STRIM’? (Strongly Typed Routing urI Mechanism?)
The only real shortcoming I’m aware of at the moment is that it does not currently handle file uploads—but you can mix in some old-style MVC routing to deal with those.
Give it a try!
I present here a wee collection of classes (‘library’ is too grand a word) for passing around database identifiers in a type-safe way in C# (and potentially Java and Scala too). See also the follow-up post from 2017.
(Right that title should have put off my casual audience who might have come here expecting a film review or a rant about religion.)
TR;DR: This post describes a new wee .NET library, to add static typing of URL routes in Microsoft MVC4. You can get it on github.
Basically it lets you:
- Define URL routes as strongly-typed, first-class-objects
- Bind routes to controller actions, fully statically-checked (so the compiler catches parameter mismatches/misspellings)
- Generate links in your Razor code (a) succinctly and (b) fully statically type-checked.
- It all works at compile time—you don’t need to run a program to generate code or anything like that.
My Mac (running OS X Lion) was exhibiting a problem whereby it paused for minutes at a time; the mouse moved, but no applications could respond (and they all showed the spinning beachball). Turned out to be a rogue ‘fontd’ process. This is how I fixed it.