orilon

C# Extension Method - Convert string to it's GUID equivalent

Jun 3rd, 2012
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.45 KB | None | 0 0
  1. /// <summary>
  2. /// Convert string to it's GUID equivalent.
  3. /// </summary>
  4. /// <param name="value">The value.</param>
  5. /// <returns></returns>
  6. private static Guid ToGuid(this string value)
  7. {
  8.     // Create a new instance of the MD5CryptoServiceProvider object.
  9.     MD5 md5Hasher = MD5.Create();
  10.     // Convert the input string to a byte array and compute the hash.
  11.     byte[] data = md5Hasher.ComputeHash(Encoding.Default.GetBytes(value));
  12.     return new Guid(data);
  13. }
Advertisement
Add Comment
Please, Sign In to add comment