MVC Style parameter binding for WebAPI

I described earlier how WebAPI binds parameters. The entire parameter binding behavior is determined by the IActionValueBinder interface and can be swapped out. The default implementation is DefaultActionValueBinder. Here’s another IActionValueBinder that provides MVC parameter binding semantics. This lets you do things that you can’t do in WebAPI’s default binder, specifically: ModelBinds everything, including the…

5

OpenSource CSV Reader on Nuget

I did some volunteer work a few years ago that required processing lots of CSV files. So I solved the problems by writing a C# CSV reader, which I wanted to share here. The basic features here are: be easy to use read and write CSV files (and support tab and “|” delimiters too) create…

5

Quiz: can you count how many combinations …

Here’s a combinatorics quiz: If you have 2 ordered lists (lengths N, M), how many ways can they be interleaved into a single list while still preserving the partial ordering from the original lists? So if the lists were:List 1: A,BList 2: X,YThe following would be valid: A,B,X,Y A,X,Y,B X,Y,A,B A,X,B,Y But ‘ yxab’ would…

10

How to add Options to Live Writer PlugIns

This entry explains how to have options associated with your Windows Live Writer plugin, including design patterns, dealing with the UI, persistence issues, and setup/uninstall implications .  See here for an example of writing a plugin.   What are good options? Some things that are nice to make as options are: Enabling / Disabling plugin…

0

WiX Script for installing Live Writer Plugins

Here’s a WiX install script to build an MSI to install a Windows Live Writer (WLW) plugin dll, by xcopying the plugin dll to the Plugins directory. You can then upload your MSI to the WLW Gallery and share your plugin with others. WLW Plugins are very easy to write, so it’s nice to have…

0

Simple Tool for text substitution plus Design questions

I wrote a simple C# app to do text substitution. It takes a (key,value) mapping and then replaces any keys in between {% … %} with their value. It’s a really trivial app. But it also quickly opens a Pandora’s box of design questions.   It takes an xml file that provides the (key,value) ,…

2

Foreach codegen

Do you know how the following C# code compiles? foreach (int i in c) { Console.WriteLine(i); }   In addition to the obvious branching opcodes, this can also emit try/finally, a call to IDisposable, unboxing opcodes.   It turns out it really depends on the type of C. There are 4 interesting cases: If C…

5

Setting transparency in an image

Just as Jackie Chan does his own stunts; I do my own image drawing. Some of my “art”:   (The yellow arrow here). The shapes in my Silverlight 1.1 app: The astute observer probably noticed that all of my work is very primitive and done in MS Paint (yup, “%windir%\system32\mspaint.exe”) . Paint is fast. It’s…

7

My first (non-trivial) Windows Live Writer Plugin

So the Live Writer Plugin model is so cool and easy that I had to write a plugin. (and do it with Edit-and-Continue). The obvious ones were already done (eg, Paste code from VS), so I scratched my head for an idea and I finally got one: a “verse of the day” plugin. This gets…

9

Sample code for copying Html to Clipboard

// Sample class for Copying and Pasting HTML fragments to and from the clipboard. // // Mike Stall. http://blogs.msdn.com/jmstall // using System; using System.Diagnostics; using System.Windows.Forms; using System.Text.RegularExpressions; using System.Collections.Generic; using System.Text; using System.IO; /// <summary> /// Helper class to decode HTML from the clipboard. /// See http://blogs.msdn.com/jmstall/archive/2007/01/21/html-clipboard.aspx for details. /// </summary> class HtmlFragment {…

1