Utility.cs 3.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Reflection;
  4. namespace BepInEx.Common
  5. {
  6. /// <summary>
  7. /// Generic helper properties and methods.
  8. /// </summary>
  9. [Obsolete("This class has moved, please use BepInEx.Utility instead of BepInEx.Common.Utility", true)]
  10. public static class Utility
  11. {
  12. /// <summary>
  13. /// The directory that the game .exe is being run from.
  14. /// </summary>
  15. [Obsolete("This property has been moved, please use Paths.GameRootPath instead", true)]
  16. public static string ExecutingDirectory
  17. => Paths.GameRootPath;
  18. /// <summary>
  19. /// The path that the plugins folder is located.
  20. /// </summary>
  21. [Obsolete("This property has been moved, please use Paths.PluginPath instead", true)]
  22. public static string PluginsDirectory
  23. => Paths.PluginPath;
  24. /// <summary>
  25. /// Combines multiple paths together, as the specfic method is not availble in .NET 3.5.
  26. /// </summary>
  27. /// <param name="parts">The multiple paths to combine together.</param>
  28. /// <returns>A combined path.</returns>
  29. [Obsolete("This method has been moved, please use BepInEx.Utility instead of BepInEx.Common.Utility", true)]
  30. public static string CombinePaths(params string[] parts) =>
  31. BepInEx.Utility.CombinePaths(parts);
  32. /// <summary>
  33. /// Tries to parse a bool, with a default value if unable to parse.
  34. /// </summary>
  35. /// <param name="input">The string to parse</param>
  36. /// <param name="defaultValue">The value to return if parsing is unsuccessful.</param>
  37. /// <returns>Boolean value of input if able to be parsed, otherwise default value.</returns>
  38. [Obsolete("This method has been moved, please use BepInEx.Utility instead of BepInEx.Common.Utility", true)]
  39. public static bool SafeParseBool(string input, bool defaultValue = false) =>
  40. BepInEx.Utility.SafeParseBool(input, defaultValue);
  41. /// <summary>
  42. /// Converts a file path into a UnityEngine.WWW format.
  43. /// </summary>
  44. /// <param name="path">The file path to convert.</param>
  45. /// <returns>A converted file path.</returns>
  46. [Obsolete("This method has been moved, please use BepInEx.Utility instead of BepInEx.Common.Utility", true)]
  47. public static string ConvertToWWWFormat(string path)
  48. => BepInEx.Utility.ConvertToWWWFormat(path);
  49. /// <summary>
  50. /// Indicates whether a specified string is null, empty, or consists only of white-space characters.
  51. /// </summary>
  52. /// <param name="self">The string to test.</param>
  53. /// <returns>True if the value parameter is null or empty, or if value consists exclusively of white-space characters.</returns>
  54. [Obsolete("This method has been moved, please use BepInEx.Utility instead of BepInEx.Common.Utility", true)]
  55. public static bool IsNullOrWhiteSpace(this string self)
  56. => BepInEx.Utility.IsNullOrWhiteSpace(self);
  57. [Obsolete("This method has been moved, please use BepInEx.Utility instead of BepInEx.Common.Utility", true)]
  58. public static IEnumerable<TNode> TopologicalSort<TNode>(IEnumerable<TNode> nodes,
  59. Func<TNode, IEnumerable<TNode>> dependencySelector)
  60. => BepInEx.Utility.TopologicalSort(nodes, dependencySelector);
  61. /// <summary>
  62. /// Try to resolve and load the given assembly DLL.
  63. /// </summary>
  64. /// <param name="assemblyName">Name of the assembly, of the type <see cref="AssemblyName" />.</param>
  65. /// <param name="directory">Directory to search the assembly from.</param>
  66. /// <param name="assembly">The loaded assembly.</param>
  67. /// <returns>True, if the assembly was found and loaded. Otherwise, false.</returns>
  68. [Obsolete("This method has been moved, please use BepInEx.Utility instead of BepInEx.Common.Utility", true)]
  69. public static bool TryResolveDllAssembly(AssemblyName assemblyName, string directory, out Assembly assembly)
  70. => BepInEx.Utility.TryResolveDllAssembly(assemblyName, directory, out assembly);
  71. }
  72. }