UrlExtensions.cs 998 B

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