Res.cs 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. using System.Globalization;
  2. using System.Resources;
  3. using System.Threading;
  4. namespace System.Configuration.InstallUtilResources
  5. {
  6. internal sealed class Res
  7. {
  8. internal const string InstallUtilSignOnMessage = "InstallUtilSignOnMessage";
  9. private static Res loader;
  10. private ResourceManager resources;
  11. private static object s_InternalSyncObject;
  12. private static object InternalSyncObject
  13. {
  14. get
  15. {
  16. if (s_InternalSyncObject == null)
  17. {
  18. object value = new object();
  19. Interlocked.CompareExchange(ref s_InternalSyncObject, value, null);
  20. }
  21. return s_InternalSyncObject;
  22. }
  23. }
  24. private static CultureInfo Culture => null;
  25. public static ResourceManager Resources => GetLoader().resources;
  26. internal Res()
  27. {
  28. resources = new ResourceManager("InstallUtil", GetType().Assembly);
  29. }
  30. private static Res GetLoader()
  31. {
  32. if (loader == null)
  33. {
  34. lock (InternalSyncObject)
  35. {
  36. if (loader == null)
  37. {
  38. loader = new Res();
  39. }
  40. }
  41. }
  42. return loader;
  43. }
  44. public static string GetString(string name, params object[] args)
  45. {
  46. Res res = GetLoader();
  47. if (res == null)
  48. {
  49. return null;
  50. }
  51. string @string = res.resources.GetString(name, Culture);
  52. if (args != null && args.Length > 0)
  53. {
  54. for (int i = 0; i < args.Length; i++)
  55. {
  56. string text = args[i] as string;
  57. if (text != null && text.Length > 1024)
  58. {
  59. args[i] = text.Substring(0, 1021) + "...";
  60. }
  61. }
  62. return string.Format(CultureInfo.CurrentCulture, @string, args);
  63. }
  64. return @string;
  65. }
  66. public static string GetString(string name)
  67. {
  68. return GetLoader()?.resources.GetString(name, Culture);
  69. }
  70. public static object GetObject(string name)
  71. {
  72. return GetLoader()?.resources.GetObject(name, Culture);
  73. }
  74. }
  75. }