Extensions.cs 1.2 KB

12345678910111213141516171819202122232425262728293031323334
  1. // --------------------------------------------------
  2. // UnityInjector - Extensions.cs
  3. // Copyright (c) Usagirei 2015 - 2015
  4. // --------------------------------------------------
  5. using System;
  6. using System.Collections.Generic;
  7. using System.IO;
  8. using System.Linq;
  9. using System.Text.RegularExpressions;
  10. namespace UnityInjector
  11. {
  12. internal static class Extensions
  13. {
  14. public static string PluginsPath { get; } = Path.Combine(Environment.CurrentDirectory, "UnityInjector");
  15. public static string UserDataPath { get; } = Path.Combine(PluginsPath, "Config");
  16. public static string Asciify(this string s) => Regex.Replace(s, @"[^0-9A-Za-z]", "_");
  17. public static string CombinePaths(params string[] parts) => parts.Aggregate(Path.Combine);
  18. public static void ForEach<T>(this IEnumerable<T> tees, Action<T> action)
  19. {
  20. foreach (var tee in tees)
  21. action(tee);
  22. }
  23. public static string PadCenter(this string str, int totalWidth, char paddingChar = ' ')
  24. {
  25. int spaces = totalWidth - str.Length;
  26. int padLeft = spaces / 2 + str.Length;
  27. return str.PadLeft(padLeft, paddingChar).PadRight(totalWidth, paddingChar);
  28. }
  29. }
  30. }