Code Snippet Plugin for Windows Live Writer

24
May
2008

Code Snippet Plugin for Windows Live Writer

While sprucing up my blog - I started looking for a code snippet plugin for Windows Live Writer - and Leo Vildosola's Code Snippet Plugin for WLW still appears to be a good choice. Like a lot of developers I use a 'dark theme' for Visual Studio and so I'm not sure that using the copy as HTML plugin from Colin Coller would work.
 

Here's an example of the WLW Code Snippet Plugin in action...

   1: /// <summary>
   2: /// Hash utility - pass the hash algorithm name as a string i.e. SHA256, SHA1, MD5 etc.
   3: /// </summary>
   4: /// <param name="input"></param>
   5: /// <param name="algorithm"></param>
   6: /// /// <param name="upperCase"></param>
   7: /// <returns>Hashed String</returns>
   8: public static string HashIt(string input, string algorithm, bool upperCase)
   9: {
  10:  
  11:     if (string.IsNullOrEmpty(input))
  12:         throw new ArgumentNullException("input");
  13:     
  14:     if(string.IsNullOrEmpty(algorithm))
  15:         throw new ArgumentNullException("algorithm");                        
  16:     
  17:     byte[] result = ((HashAlgorithm)CryptoConfig.CreateFromName(algorithm)).ComputeHash(Encoding.UTF8.GetBytes(input));
  18:  
  19:     StringBuilder myHexHash = new StringBuilder(64); //Maximum length required for SHA2-256, SHA1 or MD5
  20:  
  21:     string formatter = string.Empty;
  22:  
  23:     if (upperCase)
  24:         formatter = "{0:X2}";
  25:     else
  26:         formatter = "{0:x2}";
  27:  
  28:     for (int i = 0; i < result.Length; i++)
  29:     {
  30:         myHexHash.AppendFormat(formatter, result[i]);
  31:     }
  32:  
  33:     return myHexHash.ToString();
  34: }
Category: