Guid.Windows.cs 1002 B

1234567891011121314151617181920212223242526272829
  1. // Licensed to the .NET Foundation under one or more agreements.
  2. // The .NET Foundation licenses this file to you under the MIT license.
  3. // See the LICENSE file in the project root for more information.
  4. namespace System
  5. {
  6. partial struct Guid
  7. {
  8. public static Guid NewGuid()
  9. {
  10. // CoCreateGuid should never return Guid.Empty, since it attempts to maintain some
  11. // uniqueness guarantees.
  12. Guid g;
  13. int hr = Interop.Ole32.CoCreateGuid(out g);
  14. // We don't expect that this will ever throw an error, none are even documented, and so we don't want to pull
  15. // in the HR to ComException mappings into the core library just for this so we will try a generic exception if
  16. // we ever hit this condition.
  17. if (hr != 0)
  18. {
  19. Exception ex = new Exception();
  20. ex.HResult = hr;
  21. throw ex;
  22. }
  23. return g;
  24. }
  25. }
  26. }