Friday, September 10, 2010

Windows Live Writer & Code Snippet Plug-In

After writing such a long article (in my past post), I realized that I needed a better way to post, format, and show my code snippets.  I’ve decided on Windows Live Writer as my blogging tool and WLW Code Snippet plug-in for displaying my code.

WLW Code Snippet plug-in:  You can get the plug-in at Leo Vildosola's Blog or at CodePlex
Here’s a sample of my code from my last post:

   1: using System;
   2: using System.Collections.Generic;
   3: using System.Linq;
   4: using System.Text;
   5: using System.Runtime.InteropServices;
   7: namespace ParameterPassing
   8: {
   9:     class Program
  10:     {
  11:         static void Main(string[] args)
  12:         {
  13:             Run();
  14:         }
  15:         public static void Run()
  16:         {
  17:             Book myBook = new Book();
  19:             GCHandle handle = GCHandle.Alloc(myBook, 
  20:                 GCHandleType.Pinned);
  21:             IntPtr address = handle.AddrOfPinnedObject();
  22:             handle.Free();
  23:             Console.WriteLine("myBook address: {0}", address);
  25:             Change(ref myBook);
  27:             handle = GCHandle.Alloc(myBook, 
  28:                 GCHandleType.Pinned);
  29:             address = handle.AddrOfPinnedObject();
  30:             Console.WriteLine("myBook address: {0}", address);
  31:             handle.Free();
  32:             Console.ReadLine();
  33:         }
  35:         public static void Change(ref Book bookObj)
  36:         {
  37:             GCHandle handle = GCHandle.Alloc(bookObj, 
  38:                 GCHandleType.Pinned);
  39:             IntPtr address = handle.AddrOfPinnedObject();
  40:             handle.Free();
  41:             Console.WriteLine("bookObj address: {0}", address);
  43:             bookObj = new Book();
  44:             handle = GCHandle.Alloc(bookObj, 
  45:                 GCHandleType.Pinned);
  46:             address = handle.AddrOfPinnedObject();
  47:             handle.Free();
  48:             Console.WriteLine("bookObj address: {0}", address);
  49:         }
  50:     }
  51: }

The advantages to using a tool like this are:
    1.  Article is easier to read
    2.  Code is easier to read
    3.  Line numbers help us to talk about specifics in the code

What tools are you using that could help my blog be more interesting and interactive?  I welcome your input.

I also have a couple of tips for working with WLW:
     1. Single space:  The default when you hit “enter” is double space.  To get single space, hit 
         [Shift] and then [Enter].
     2. To help streamline the blog by shortening up all the blog posts on the Home page, use
         “jump break”.  Problem is, WLW doesn’t have jump break built into (yet), i.e. the tool is
         grayed out.  What I do is go the “Source” to view the HTML.  Then place <!—more –>
         just after the parameter or sentence that I want on my Home page.

kick it on

Shout it

No comments:

Post a Comment


My photo
Welcome to my blog! This blog is about my journey to become a Master .NET coder and teacher.


There was an error in this gadget