UrlExtensions.cs 1.1 KB

123456789101112131415161718192021222324252627282930313233
  1. using System;
  2. namespace Emby.Server.Implementations.Services
  3. {
  4. /// <summary>
  5. /// Donated by Ivan Korneliuk from his post:
  6. /// http://korneliuk.blogspot.com/2012/08/servicestack-reusing-dtos.html
  7. ///
  8. /// Modified to only allow using routes matching the supplied HTTP Verb
  9. /// </summary>
  10. public static class UrlExtensions
  11. {
  12. public static string GetMethodName(this Type type)
  13. {
  14. var typeName = type.FullName != null //can be null, e.g. generic types
  15. ? LeftPart(type.FullName, "[[") //Generic Fullname
  16. .Replace(type.Namespace + ".", "") //Trim Namespaces
  17. .Replace("+", ".") //Convert nested into normal type
  18. : type.Name;
  19. return type.IsGenericParameter ? "'" + typeName : typeName;
  20. }
  21. private static string LeftPart(string strVal, string needle)
  22. {
  23. if (strVal == null) return null;
  24. var pos = strVal.IndexOf(needle, StringComparison.OrdinalIgnoreCase);
  25. return pos == -1
  26. ? strVal
  27. : strVal.Substring(0, pos);
  28. }
  29. }
  30. }