UrlExtensions.cs 1.0 KB

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