Code:
/ DotNET / DotNET / 8.0 / untmp / whidbey / REDBITS / 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); } }
Link Menu

This book is available now!
Buy at Amazon US or
Buy at Amazon UK
- IdentifierService.cs
- PropertyInformationCollection.cs
- SmtpMail.cs
- AggregatePushdown.cs
- NativeMethods.cs
- ComplexTypeEmitter.cs
- HttpApplicationFactory.cs
- FixUpCollection.cs
- PreProcessInputEventArgs.cs
- SerializationObjectManager.cs
- DataQuery.cs
- PackageRelationship.cs
- WebBrowserProgressChangedEventHandler.cs
- SafeViewOfFileHandle.cs
- DataTableTypeConverter.cs
- BridgeDataReader.cs
- Point3D.cs
- ResourceManagerWrapper.cs
- UserPreferenceChangedEventArgs.cs
- HttpProfileGroupBase.cs
- ConfigXmlSignificantWhitespace.cs
- Crc32.cs
- SourceItem.cs
- CommandBindingCollection.cs
- TypeDescriptionProviderAttribute.cs
- updateconfighost.cs
- SafeFileHandle.cs
- CounterSampleCalculator.cs
- TextServicesPropertyRanges.cs
- DataList.cs
- ProtocolsConfiguration.cs
- DataPointer.cs
- SqlDataSource.cs
- TablePatternIdentifiers.cs
- DefaultAuthorizationContext.cs
- DeflateEmulationStream.cs
- ResourceDisplayNameAttribute.cs
- __Filters.cs
- DataGridState.cs
- Clipboard.cs
- SEHException.cs
- EventsTab.cs
- VoiceChangeEventArgs.cs
- PeerNearMe.cs
- SerialReceived.cs
- HttpRequestWrapper.cs
- ReachIDocumentPaginatorSerializer.cs
- WSMessageEncoding.cs
- KeyValuePair.cs
- _ListenerResponseStream.cs
- XmlSchemaSimpleTypeUnion.cs
- ObjectStateEntry.cs
- ListViewTableCell.cs
- BeginStoryboard.cs
- PassportPrincipal.cs
- CachedPathData.cs
- SecurityKeyIdentifier.cs
- Int16AnimationBase.cs
- ServiceContractViewControl.cs
- EntitySetBase.cs
- ComboBox.cs
- MessageLogTraceRecord.cs
- XMLDiffLoader.cs
- PageAsyncTask.cs
- SQLDecimalStorage.cs
- PropertyValueChangedEvent.cs
- UshortList2.cs
- cookiecontainer.cs
- MsmqOutputSessionChannel.cs
- TreeViewEvent.cs
- MessageBox.cs
- DPCustomTypeDescriptor.cs
- FixedSOMElement.cs
- IntegerFacetDescriptionElement.cs
- ToolStripDropTargetManager.cs
- TextBlockAutomationPeer.cs
- NumberAction.cs
- NetworkInformationPermission.cs
- OleDbFactory.cs
- XmlHierarchicalDataSourceView.cs
- SmiEventSink_DeferedProcessing.cs
- PenThread.cs
- FormsAuthenticationEventArgs.cs
- HtmlButton.cs
- XmlConvert.cs
- PathGeometry.cs
- DivideByZeroException.cs
- Baml6ConstructorInfo.cs
- BidPrivateBase.cs
- Application.cs
- XmlIncludeAttribute.cs
- AnnotationDocumentPaginator.cs
- HyperlinkAutomationPeer.cs
- TextBoxAutomationPeer.cs
- WebEncodingValidator.cs
- ErrorHandler.cs
- ScrollProviderWrapper.cs
- ToolStripContainerDesigner.cs
- AuthenticationModuleElement.cs
- QilFactory.cs