The Labs \ Source Viewer \ SSCLI \ System.Diagnostics \ AssertWrapper

  1. // ==++==
  2. //
  3. //
  4. // Copyright (c) 2006 Microsoft Corporation. All rights reserved.
  5. //
  6. // The use and distribution terms for this software are contained in the file
  7. // named license.txt, which can be found in the root of this distribution.
  8. // By using this software in any fashion, you are agreeing to be bound by the
  9. // terms of this license.
  10. //
  11. // You must not remove this notice, or any other, from this software.
  12. //
  13. //
  14. // ==--==
  15. using System;
  16. using System.Diagnostics;
  17. using System.Runtime.InteropServices;
  18. using Microsoft.Win32;
  19. using System.Security.Permissions;
  20. using System.Security;
  21. using System.Collections;
  22. using System.Globalization;
  23. using System.Runtime.Versioning;
  24. namespace System.Diagnostics
  25. {
  26.    
  27.     static internal class AssertWrapper
  28.     {
  29.        
  30.        
  31.         public static void ShowAssert(string stackTrace, StackFrame frame, string message, string detailMessage)
  32.         {
  33.             ShowMessageBoxAssert(stackTrace, message, detailMessage);
  34.         }
  35.        
  36.        
  37.        
  38.         [ResourceExposure(ResourceScope.None)]
  39.         private static void ShowMessageBoxAssert(string stackTrace, string message, string detailMessage)
  40.         {
  41.             string fullMessage = message + "\r\n" + detailMessage + "\r\n" + stackTrace;
  42.            
  43.            
  44.                 /*AbortRetryIgnore*/                /*DefaultButton3*/                /*IconHand*/                /* TopMost */            int flags = 2 | 512 | 16 | 262144;
  45.            
  46.            
  47.             if (IsRTLResources)
  48.                 flags = flags | SafeNativeMethods.MB_RIGHT | SafeNativeMethods.MB_RTLREADING;
  49.            
  50.             int rval = SafeNativeMethods.MessageBox(NativeMethods.NullHandleRef, fullMessage, SR.GetString(SR.DebugAssertTitle), flags);
  51.             switch (rval) {
  52.                 case 3:
  53.                     // abort
  54.                     new SecurityPermission(SecurityPermissionFlag.UnmanagedCode).Assert();
  55.                     try {
  56.                         Environment.Exit(1);
  57.                     }
  58.                     finally {
  59.                         CodeAccessPermission.RevertAssert();
  60.                     }
  61.                     break;
  62.                 case 4:
  63.                     // retry
  64.                     if (!System.Diagnostics.Debugger.IsAttached) {
  65.                         System.Diagnostics.Debugger.Launch();
  66.                     }
  67.                     System.Diagnostics.Debugger.Break();
  68.                     break;
  69.             }
  70.         }
  71.        
  72.        
  73.         private static bool IsRTLResources {
  74.             get { return SR.GetString(SR.RTL) != "RTL_False"; }
  75.         }
  76.        
  77.     }
  78. }

Developer Fusion