GuidExtension.cs 804 B

123456789101112131415161718192021222324252627282930
  1. namespace PlcSiemens.Core.Extension
  2. {
  3. public static class GuidExtension
  4. {
  5. /// <summary>
  6. /// GuidÊÕËõµ½string
  7. /// </summary>
  8. /// <param name="target"></param>
  9. /// <returns></returns>
  10. public static string Shrink(this Guid target)
  11. {
  12. if (target.IsEmpty()) return "";
  13. var base64 = Convert.ToBase64String(target.ToByteArray());
  14. var encoded = base64.Replace("/", "_").Replace("+", "-");
  15. return encoded.Substring(0, 22);
  16. }
  17. /// <summary>
  18. /// GuidÊÇ·ñΪ¿Õ
  19. /// </summary>
  20. /// <param name="target"></param>
  21. /// <returns></returns>
  22. public static bool IsEmpty(this Guid target)
  23. {
  24. return target == Guid.Empty;
  25. }
  26. }
  27. }