Code:
/ Net / Net / 3.5.50727.3053 / DEVDIV / depot / DevDiv / releases / whidbey / netfxsp / ndp / clr / src / BCL / System / Diagnostics / Assert.cs / 1 / Assert.cs
// ==++==
//
// Copyright (c) Microsoft Corporation. All rights reserved.
//
// ==--==
namespace System.Diagnostics {
using System;
using System.Security.Permissions;
using System.IO;
using System.Reflection;
using System.Runtime.CompilerServices;
// Class which handles code asserts. Asserts are used to explicitly protect
// assumptions made in the code. In general if an assert fails, it indicates
// a program bug so is immediately called to the attention of the user.
// Only static data members, does not need to be marked with the serializable attribute
internal static class Assert
{
private static AssertFilter[] ListOfFilters;
private static int iNumOfFilters;
private static int iFilterArraySize;
static Assert()
{
Assert.AddFilter(new DefaultFilter());
}
// AddFilter adds a new assert filter. This replaces the current
// filter, unless the filter returns FailContinue.
//
public static void AddFilter(AssertFilter filter)
{
if (iFilterArraySize <= iNumOfFilters)
{
AssertFilter[] newFilterArray = new AssertFilter [iFilterArraySize+2];
if (iNumOfFilters > 0)
Array.Copy(ListOfFilters, newFilterArray, iNumOfFilters);
iFilterArraySize += 2;
ListOfFilters = newFilterArray;
}
ListOfFilters [iNumOfFilters++] = filter;
}
// Called when an assertion is being made.
//
public static void Check(bool condition, String conditionString, String message)
{
if (!condition)
{
Fail (conditionString, message);
}
}
public static void Fail(String conditionString, String message)
{
// get the stacktrace
StackTrace st = new StackTrace();
// Run through the list of filters backwards (the last filter in the list
// is the default filter. So we're guaranteed that there will be atleast
// one filter to handle the assert.
int iTemp = iNumOfFilters;
while (iTemp > 0)
{
AssertFilters iResult = ListOfFilters [--iTemp].AssertFailure (conditionString, message, st);
if (iResult == AssertFilters.FailDebug)
{
if (Debugger.IsAttached == true)
Debugger.Break();
else
{
if (Debugger.Launch() == false)
{
throw new InvalidOperationException(
Environment.GetResourceString("InvalidOperation_DebuggerLaunchFailed"));
}
}
break;
}
else if (iResult == AssertFilters.FailTerminate)
Environment.Exit(-1);
else if (iResult == AssertFilters.FailIgnore)
break;
// If none of the above, it means that the Filter returned FailContinue.
// So invoke the next filter.
}
}
// Called when an assert happens.
//
[MethodImplAttribute(MethodImplOptions.InternalCall)]
public extern static int ShowDefaultAssertDialog(String conditionString, String message);
}
}
// File provided for Reference Use Only by Microsoft Corporation (c) 2007.
// ==++==
//
// Copyright (c) Microsoft Corporation. All rights reserved.
//
// ==--==
namespace System.Diagnostics {
using System;
using System.Security.Permissions;
using System.IO;
using System.Reflection;
using System.Runtime.CompilerServices;
// Class which handles code asserts. Asserts are used to explicitly protect
// assumptions made in the code. In general if an assert fails, it indicates
// a program bug so is immediately called to the attention of the user.
// Only static data members, does not need to be marked with the serializable attribute
internal static class Assert
{
private static AssertFilter[] ListOfFilters;
private static int iNumOfFilters;
private static int iFilterArraySize;
static Assert()
{
Assert.AddFilter(new DefaultFilter());
}
// AddFilter adds a new assert filter. This replaces the current
// filter, unless the filter returns FailContinue.
//
public static void AddFilter(AssertFilter filter)
{
if (iFilterArraySize <= iNumOfFilters)
{
AssertFilter[] newFilterArray = new AssertFilter [iFilterArraySize+2];
if (iNumOfFilters > 0)
Array.Copy(ListOfFilters, newFilterArray, iNumOfFilters);
iFilterArraySize += 2;
ListOfFilters = newFilterArray;
}
ListOfFilters [iNumOfFilters++] = filter;
}
// Called when an assertion is being made.
//
public static void Check(bool condition, String conditionString, String message)
{
if (!condition)
{
Fail (conditionString, message);
}
}
public static void Fail(String conditionString, String message)
{
// get the stacktrace
StackTrace st = new StackTrace();
// Run through the list of filters backwards (the last filter in the list
// is the default filter. So we're guaranteed that there will be atleast
// one filter to handle the assert.
int iTemp = iNumOfFilters;
while (iTemp > 0)
{
AssertFilters iResult = ListOfFilters [--iTemp].AssertFailure (conditionString, message, st);
if (iResult == AssertFilters.FailDebug)
{
if (Debugger.IsAttached == true)
Debugger.Break();
else
{
if (Debugger.Launch() == false)
{
throw new InvalidOperationException(
Environment.GetResourceString("InvalidOperation_DebuggerLaunchFailed"));
}
}
break;
}
else if (iResult == AssertFilters.FailTerminate)
Environment.Exit(-1);
else if (iResult == AssertFilters.FailIgnore)
break;
// If none of the above, it means that the Filter returned FailContinue.
// So invoke the next filter.
}
}
// Called when an assert happens.
//
[MethodImplAttribute(MethodImplOptions.InternalCall)]
public extern static int ShowDefaultAssertDialog(String conditionString, String message);
}
}
// File provided for Reference Use Only by Microsoft Corporation (c) 2007.
Link Menu

This book is available now!
Buy at Amazon US or
Buy at Amazon UK
- CalendarDateChangedEventArgs.cs
- UIPermission.cs
- WsatAdminException.cs
- _Semaphore.cs
- Win32SafeHandles.cs
- Executor.cs
- MatrixAnimationUsingKeyFrames.cs
- FixedPosition.cs
- DataBoundControlHelper.cs
- XamlClipboardData.cs
- DataBindEngine.cs
- ApplicationId.cs
- OdbcConnectionPoolProviderInfo.cs
- Image.cs
- PriorityBinding.cs
- GridViewColumnCollection.cs
- GregorianCalendar.cs
- CatalogPartCollection.cs
- ObjectHelper.cs
- GcSettings.cs
- XmlSchemaInferenceException.cs
- HMACSHA1.cs
- ViewGenResults.cs
- WebPartAuthorizationEventArgs.cs
- WebPartsPersonalization.cs
- wgx_commands.cs
- Control.cs
- TextRangeEditLists.cs
- HexParser.cs
- RoutedEvent.cs
- FamilyTypeface.cs
- CodeNamespaceImportCollection.cs
- ListView.cs
- CounterSample.cs
- ThemeDirectoryCompiler.cs
- SendSecurityHeader.cs
- AnnotationService.cs
- TableLayoutPanelCodeDomSerializer.cs
- MethodRental.cs
- PointHitTestResult.cs
- DataGridViewComboBoxColumn.cs
- RequestNavigateEventArgs.cs
- SpellCheck.cs
- SQLByte.cs
- SqlProviderServices.cs
- SHA512.cs
- WsdlImporter.cs
- Label.cs
- CommentGlyph.cs
- Lease.cs
- ConnectionPointCookie.cs
- ApplicationServicesHostFactory.cs
- Brushes.cs
- ConfigXmlElement.cs
- DefaultHttpHandler.cs
- ThicknessAnimation.cs
- ISFClipboardData.cs
- OdbcTransaction.cs
- WindowsGrip.cs
- AccessibilityHelperForVista.cs
- NestPullup.cs
- X509Utils.cs
- ListBoxItem.cs
- ProgressBar.cs
- OdbcPermission.cs
- AggregateNode.cs
- AssemblyHash.cs
- Deflater.cs
- Selector.cs
- EntryIndex.cs
- RadioButtonAutomationPeer.cs
- RelatedPropertyManager.cs
- DbConnectionPoolGroupProviderInfo.cs
- WebConfigurationHost.cs
- LambdaCompiler.Lambda.cs
- BitStack.cs
- SqlHelper.cs
- CommandBinding.cs
- TCPClient.cs
- NavigationCommands.cs
- Effect.cs
- FreezableDefaultValueFactory.cs
- TextWriterEngine.cs
- MemoryRecordBuffer.cs
- DragEvent.cs
- SqlDependency.cs
- ResolveNameEventArgs.cs
- EncryptedType.cs
- HtmlAnchor.cs
- mactripleDES.cs
- CharacterBufferReference.cs
- DynamicMetaObjectBinder.cs
- Axis.cs
- WorkflowRuntime.cs
- Stroke.cs
- IdentityValidationException.cs
- Queue.cs
- EntityDesignerBuildProvider.cs
- CodeTypeConstructor.cs
- GenericIdentity.cs