AnimancerHelpUrlAttribute.cs 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. // Animancer // https://kybernetik.com.au/animancer // Copyright 2018-2024 Kybernetik //
  2. using System;
  3. using UnityEngine;
  4. namespace Animancer
  5. {
  6. /// <summary>[Assert-Conditional]
  7. /// A <see cref="HelpURLAttribute"/> which points to Animancer's documentation.
  8. /// </summary>
  9. [AttributeUsage(AttributeTargets.All, AllowMultiple = false)]
  10. [System.Diagnostics.Conditional(Strings.Assertions)]
  11. public class AnimancerHelpUrlAttribute : HelpURLAttribute
  12. {
  13. /************************************************************************************************************************/
  14. /// <summary>Creates a new <see cref="AnimancerHelpUrlAttribute"/>.</summary>
  15. public AnimancerHelpUrlAttribute(string url)
  16. : base(url)
  17. { }
  18. /************************************************************************************************************************/
  19. /// <summary>Creates a new <see cref="AnimancerHelpUrlAttribute"/>.</summary>
  20. public AnimancerHelpUrlAttribute(Type type)
  21. : base(GetApiDocumentationUrl(type))
  22. { }
  23. /************************************************************************************************************************/
  24. /// <summary>Returns a URL for the given `type`'s API Documentation page.</summary>
  25. public static string GetApiDocumentationUrl(Type type)
  26. => GetApiDocumentationUrl(Strings.DocsURLs.Documentation + "/api/", type);
  27. /// <summary>Returns a URL for the given `type`'s API Documentation page.</summary>
  28. public static string GetApiDocumentationUrl(string prefix, Type type)
  29. {
  30. var url = StringBuilderPool.Instance.Acquire();
  31. url.Append(prefix);
  32. if (!string.IsNullOrEmpty(type.Namespace))
  33. url.Append(type.Namespace).Append('/');
  34. url.Append(type.Name.Replace('`', '_'));
  35. return url.ReleaseToString();
  36. }
  37. /************************************************************************************************************************/
  38. }
  39. }