Code:
/ 4.0 / 4.0 / DEVDIV_TFS / Dev10 / Releases / RTMRel / wpf / src / Framework / System / Windows / Documents / ValidationHelper.cs / 1305600 / ValidationHelper.cs
//---------------------------------------------------------------------------- // // File: ValidationHelper.cs // // Copyright (C) Microsoft Corporation. All rights reserved. // // Description: Helpers for TOM parameter validation. // //--------------------------------------------------------------------------- namespace System.Windows.Documents { using MS.Internal; // Invariant.Assert using System.ComponentModel; using System.Windows; using System.Windows.Media; internal static class ValidationHelper { //----------------------------------------------------- // // Internal Methods // //----------------------------------------------------- #region Internal Methods // Verifies a TextPointer is non-null and // is associated with a given TextContainer. // // Throws an appropriate exception if a test fails. internal static void VerifyPosition(ITextContainer tree, ITextPointer position) { VerifyPosition(tree, position, "position"); } // Verifies a TextPointer is non-null and is associated with a given TextContainer. // // Throws an appropriate exception if a test fails. internal static void VerifyPosition(ITextContainer container, ITextPointer position, string paramName) { if (position == null) { throw new ArgumentNullException(paramName); } if (position.TextContainer != container) { throw new ArgumentException(SR.Get(SRID.NotInAssociatedTree, paramName)); } } // Verifies two positions are safe to use as a logical text span. // // Throws ArgumentNullException if startPosition == null || endPosition == null // ArgumentException if startPosition.TextContainer != endPosition.TextContainer or // startPosition > endPosition internal static void VerifyPositionPair(ITextPointer startPosition, ITextPointer endPosition) { if (startPosition == null) { throw new ArgumentNullException("startPosition"); } if (endPosition == null) { throw new ArgumentNullException("endPosition"); } if (startPosition.TextContainer != endPosition.TextContainer) { throw new ArgumentException(SR.Get(SRID.InDifferentTextContainers, "startPosition", "endPosition")); } if (startPosition.CompareTo(endPosition) > 0) { throw new ArgumentException(SR.Get(SRID.BadTextPositionOrder, "startPosition", "endPosition")); } } // Throws an ArgumentException if direction is not a valid enum. internal static void VerifyDirection(LogicalDirection direction, string argumentName) { if (direction != LogicalDirection.Forward && direction != LogicalDirection.Backward) { throw new InvalidEnumArgumentException(argumentName, (int)direction, typeof(LogicalDirection)); } } // Throws an ArgumentException if edge is not a valid enum. internal static void VerifyElementEdge(ElementEdge edge, string param) { if (edge != ElementEdge.BeforeStart && edge != ElementEdge.AfterStart && edge != ElementEdge.BeforeEnd && edge != ElementEdge.AfterEnd) { throw new InvalidEnumArgumentException(param, (int)edge, typeof(ElementEdge)); } } // ............................................................... // // TextSchema Validation // // ............................................................... // Checks whether it is valid to insert the child object at passed position. internal static void ValidateChild(TextPointer position, object child, string paramName) { Invariant.Assert(position != null); if (child == null) { throw new ArgumentNullException(paramName); } if (!TextSchema.IsValidChild(/*position:*/position, /*childType:*/child.GetType())) { throw new ArgumentException(SR.Get(SRID.TextSchema_ChildTypeIsInvalid, position.Parent.GetType().Name, child.GetType().Name)); } // The new child should not be currently in other text tree if (child is TextElement) { if (((TextElement)child).Parent != null) { throw new ArgumentException(SR.Get(SRID.TextSchema_TheChildElementBelongsToAnotherTreeAlready, child.GetType().Name)); } } else { Invariant.Assert(child is UIElement); // Cannot call UIElement.Parent across assembly boundary. So skip this part of validation. This condition will be checked elsewhere anyway. //if (((UIElement)child).Parent != null) //{ // throw new ArgumentException(SR.Get(SRID.TextSchema_TheChildElementBelongsToAnotherTreeAlready, child.GetType().Name)); //} } } #endregion Internal methods } } // File provided for Reference Use Only by Microsoft Corporation (c) 2007. // Copyright (c) Microsoft Corporation. All rights reserved. //---------------------------------------------------------------------------- // // File: ValidationHelper.cs // // Copyright (C) Microsoft Corporation. All rights reserved. // // Description: Helpers for TOM parameter validation. // //--------------------------------------------------------------------------- namespace System.Windows.Documents { using MS.Internal; // Invariant.Assert using System.ComponentModel; using System.Windows; using System.Windows.Media; internal static class ValidationHelper { //----------------------------------------------------- // // Internal Methods // //----------------------------------------------------- #region Internal Methods // Verifies a TextPointer is non-null and // is associated with a given TextContainer. // // Throws an appropriate exception if a test fails. internal static void VerifyPosition(ITextContainer tree, ITextPointer position) { VerifyPosition(tree, position, "position"); } // Verifies a TextPointer is non-null and is associated with a given TextContainer. // // Throws an appropriate exception if a test fails. internal static void VerifyPosition(ITextContainer container, ITextPointer position, string paramName) { if (position == null) { throw new ArgumentNullException(paramName); } if (position.TextContainer != container) { throw new ArgumentException(SR.Get(SRID.NotInAssociatedTree, paramName)); } } // Verifies two positions are safe to use as a logical text span. // // Throws ArgumentNullException if startPosition == null || endPosition == null // ArgumentException if startPosition.TextContainer != endPosition.TextContainer or // startPosition > endPosition internal static void VerifyPositionPair(ITextPointer startPosition, ITextPointer endPosition) { if (startPosition == null) { throw new ArgumentNullException("startPosition"); } if (endPosition == null) { throw new ArgumentNullException("endPosition"); } if (startPosition.TextContainer != endPosition.TextContainer) { throw new ArgumentException(SR.Get(SRID.InDifferentTextContainers, "startPosition", "endPosition")); } if (startPosition.CompareTo(endPosition) > 0) { throw new ArgumentException(SR.Get(SRID.BadTextPositionOrder, "startPosition", "endPosition")); } } // Throws an ArgumentException if direction is not a valid enum. internal static void VerifyDirection(LogicalDirection direction, string argumentName) { if (direction != LogicalDirection.Forward && direction != LogicalDirection.Backward) { throw new InvalidEnumArgumentException(argumentName, (int)direction, typeof(LogicalDirection)); } } // Throws an ArgumentException if edge is not a valid enum. internal static void VerifyElementEdge(ElementEdge edge, string param) { if (edge != ElementEdge.BeforeStart && edge != ElementEdge.AfterStart && edge != ElementEdge.BeforeEnd && edge != ElementEdge.AfterEnd) { throw new InvalidEnumArgumentException(param, (int)edge, typeof(ElementEdge)); } } // ............................................................... // // TextSchema Validation // // ............................................................... // Checks whether it is valid to insert the child object at passed position. internal static void ValidateChild(TextPointer position, object child, string paramName) { Invariant.Assert(position != null); if (child == null) { throw new ArgumentNullException(paramName); } if (!TextSchema.IsValidChild(/*position:*/position, /*childType:*/child.GetType())) { throw new ArgumentException(SR.Get(SRID.TextSchema_ChildTypeIsInvalid, position.Parent.GetType().Name, child.GetType().Name)); } // The new child should not be currently in other text tree if (child is TextElement) { if (((TextElement)child).Parent != null) { throw new ArgumentException(SR.Get(SRID.TextSchema_TheChildElementBelongsToAnotherTreeAlready, child.GetType().Name)); } } else { Invariant.Assert(child is UIElement); // Cannot call UIElement.Parent across assembly boundary. So skip this part of validation. This condition will be checked elsewhere anyway. //if (((UIElement)child).Parent != null) //{ // throw new ArgumentException(SR.Get(SRID.TextSchema_TheChildElementBelongsToAnotherTreeAlready, child.GetType().Name)); //} } } #endregion Internal methods } } // File provided for Reference Use Only by Microsoft Corporation (c) 2007. // Copyright (c) Microsoft Corporation. All rights reserved.
Link Menu
This book is available now!
Buy at Amazon US or
Buy at Amazon UK
- ISFClipboardData.cs
- StructuredTypeEmitter.cs
- MetadataArtifactLoaderXmlReaderWrapper.cs
- FixedDocumentPaginator.cs
- ProcessInputEventArgs.cs
- X509Certificate2.cs
- ValidationService.cs
- EntitySqlQueryBuilder.cs
- WmlMobileTextWriter.cs
- HttpException.cs
- AlignmentXValidation.cs
- SEHException.cs
- WebPartDeleteVerb.cs
- DataGridTextBox.cs
- DoubleStorage.cs
- StorageEntityTypeMapping.cs
- WebBrowserUriTypeConverter.cs
- InfoCard.cs
- PowerEase.cs
- DeleteHelper.cs
- IsolatedStorageFile.cs
- SubpageParaClient.cs
- ErrorFormatterPage.cs
- ListControl.cs
- EventLogPermissionAttribute.cs
- OleDbRowUpdatedEvent.cs
- DataGridView.cs
- XmlSchemaSet.cs
- UnsafeNativeMethods.cs
- Byte.cs
- ReliableMessagingVersionConverter.cs
- PropertyDescriptorCollection.cs
- CommandHelpers.cs
- WebPartDisplayModeCollection.cs
- AppModelKnownContentFactory.cs
- GetLastErrorDetailsRequest.cs
- SerialPinChanges.cs
- DataGridTable.cs
- ComponentRenameEvent.cs
- DataColumnCollection.cs
- FixedDocumentSequencePaginator.cs
- Error.cs
- mediaeventargs.cs
- HtmlFormAdapter.cs
- EntityDataSourceSelectingEventArgs.cs
- Aes.cs
- MultiTrigger.cs
- AdjustableArrowCap.cs
- BaseServiceProvider.cs
- PropertyDescriptor.cs
- PipeStream.cs
- AtomServiceDocumentSerializer.cs
- HtmlShimManager.cs
- DesignerActionListCollection.cs
- UTF7Encoding.cs
- WebPartEventArgs.cs
- ServiceModelTimeSpanValidator.cs
- IdnMapping.cs
- securestring.cs
- ParallelEnumerableWrapper.cs
- RightNameExpirationInfoPair.cs
- TdsParserStaticMethods.cs
- ListViewItem.cs
- CacheMode.cs
- DataGridBoolColumn.cs
- SystemException.cs
- ThreadInterruptedException.cs
- CfgRule.cs
- AutoCompleteStringCollection.cs
- CodeConditionStatement.cs
- TextWriterTraceListener.cs
- Recipient.cs
- CaseInsensitiveHashCodeProvider.cs
- ErrorInfoXmlDocument.cs
- Enlistment.cs
- CookieProtection.cs
- TrustExchangeException.cs
- TraceFilter.cs
- Privilege.cs
- MarkupExtensionParser.cs
- ExternalFile.cs
- MaterialGroup.cs
- MenuItem.cs
- safesecurityhelperavalon.cs
- SafeFileMappingHandle.cs
- SchemaImporterExtension.cs
- MobileDeviceCapabilitiesSectionHandler.cs
- CodeSpit.cs
- CodeGeneratorOptions.cs
- DocumentsTrace.cs
- CustomError.cs
- DecoderReplacementFallback.cs
- CodeArrayCreateExpression.cs
- PreservationFileReader.cs
- OutputCacheProfileCollection.cs
- QilList.cs
- OrderPreservingPipeliningMergeHelper.cs
- ListManagerBindingsCollection.cs
- Soap.cs
- EnumValidator.cs