Freigeben über


Blogging Code Samples

So, I tried to big-up Word 2007's blog publishing features in my last post and somewhat put my foot in it. Word 2007 in general does an excellent job of posting to blogs, but when I cut and paste from Visual Studio 2005 into Word 2007 what popped out of my blog was ok but not brilliant.

I tried playing with Word 2007 to see if I was missing something, but I've not discovered any "paste code as HTML and make it look good" option (so far).

In the end I've decided to try Colin Coller's CopySourceAsHtml VS.NET addin. It's very good, and does just want I want. Here's a sample of some code copied from VS.NET using this addin...

using System;

using System.Collections;

 

public delegate int Transformer(int input);

 

public class Simple : IEnumerable {

 

    private int data;

 

    public Simple(int data) {

        this.data = data;

    }

 

    public override string ToString() {

        return String.Format("Simple<{0}>", data);

    }

 

    public IEnumerator GetEnumerator() {

        for (int i = 0; i < data; i ++) {

            yield return new Simple(i);

        }

    }

 

    public int Transform(Transformer t) {

        return t(data);

    }

 

    public static Simple operator +(Simple a, Simple b) {

        return new Simple(a.data + b.data);

    }

}