NameGenerator.cs 832 B

1234567891011121314151617181920212223242526272829
  1. //-----------------------------------------------------------------------------
  2. // Copyright (c) Microsoft Corporation. All rights reserved.
  3. //-----------------------------------------------------------------------------
  4. namespace System.Runtime
  5. {
  6. using System;
  7. using System.Globalization;
  8. using System.Threading;
  9. class NameGenerator
  10. {
  11. static NameGenerator nameGenerator = new NameGenerator();
  12. long id;
  13. string prefix;
  14. NameGenerator()
  15. {
  16. this.prefix = string.Concat("_", Guid.NewGuid().ToString().Replace('-', '_'), "_");
  17. }
  18. public static string Next()
  19. {
  20. long nextId = Interlocked.Increment(ref nameGenerator.id);
  21. return nameGenerator.prefix + nextId.ToString(CultureInfo.InvariantCulture);
  22. }
  23. }
  24. }