Code:
/ Dotnetfx_Vista_SP2 / Dotnetfx_Vista_SP2 / 8.0.50727.4016 / DEVDIV / depot / DevDiv / releases / whidbey / NetFxQFE / 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
- PersonalizationStateInfo.cs
- DataGridViewCellValidatingEventArgs.cs
- TableHeaderCell.cs
- MissingManifestResourceException.cs
- ReaderContextStackData.cs
- DataFormat.cs
- XmlSerializer.cs
- Triplet.cs
- ConstraintEnumerator.cs
- QueryCursorEventArgs.cs
- SqlRowUpdatingEvent.cs
- MetadataSet.cs
- AmbientValueAttribute.cs
- PageBreakRecord.cs
- XmlDataCollection.cs
- BinaryObjectInfo.cs
- MultipartContentParser.cs
- InvokeGenerator.cs
- ConnectionStringsExpressionBuilder.cs
- DataBoundControlHelper.cs
- NamespaceEmitter.cs
- EmptyStringExpandableObjectConverter.cs
- OpCodes.cs
- AnnotationResource.cs
- Utils.cs
- StringDictionary.cs
- CallbackValidator.cs
- ResXBuildProvider.cs
- Parameter.cs
- InvalidDataException.cs
- DataGridBoolColumn.cs
- ManagementOptions.cs
- CngProvider.cs
- HotCommands.cs
- NativeActivityAbortContext.cs
- Command.cs
- RefreshInfo.cs
- ViewStateModeByIdAttribute.cs
- SqlDataReaderSmi.cs
- DependencyObjectProvider.cs
- MouseCaptureWithinProperty.cs
- XmlNamespaceMappingCollection.cs
- XamlWrappingReader.cs
- Convert.cs
- Typeface.cs
- RSAPKCS1SignatureDeformatter.cs
- HostingEnvironmentException.cs
- HMACMD5.cs
- KeyedHashAlgorithm.cs
- XmlSchemaInferenceException.cs
- TypeConverterValueSerializer.cs
- InvokeHandlers.cs
- DataSourceControl.cs
- SslStream.cs
- BooleanAnimationBase.cs
- ImageIndexConverter.cs
- DeferrableContent.cs
- CapiSymmetricAlgorithm.cs
- SerializationFieldInfo.cs
- TypeRefElement.cs
- MetaTableHelper.cs
- EditorPartCollection.cs
- RouteCollection.cs
- DesignerEditorPartChrome.cs
- FrameworkElementFactoryMarkupObject.cs
- DependencyPropertyChangedEventArgs.cs
- SoapInteropTypes.cs
- PropertyStore.cs
- FormParameter.cs
- DockEditor.cs
- PropertyContainer.cs
- TriggerActionCollection.cs
- DictionaryKeyPropertyAttribute.cs
- SqlDataReaderSmi.cs
- FilterFactory.cs
- _ChunkParse.cs
- ZeroOpNode.cs
- NavigatingCancelEventArgs.cs
- RpcCryptoContext.cs
- ItemsPanelTemplate.cs
- DataGridViewDesigner.cs
- ClientRolePrincipal.cs
- SubMenuStyleCollectionEditor.cs
- SelectingProviderEventArgs.cs
- RouteData.cs
- ItemCheckEvent.cs
- CounterCreationDataCollection.cs
- TextServicesProperty.cs
- HttpCapabilitiesBase.cs
- ParallelEnumerable.cs
- AutomationPropertyChangedEventArgs.cs
- cryptoapiTransform.cs
- MethodExpression.cs
- MenuItemBindingCollection.cs
- DataContractSerializerOperationGenerator.cs
- RowCache.cs
- ShutDownListener.cs
- CodeDelegateCreateExpression.cs
- Policy.cs
- ProcessHost.cs