Code:
/ Dotnetfx_Win7_3.5.1 / Dotnetfx_Win7_3.5.1 / 3.5.1 / DEVDIV / depot / DevDiv / releases / whidbey / NetFXspW7 / ndp / fx / src / Data / System / Data / ConstraintEnumerator.cs / 1 / ConstraintEnumerator.cs
//------------------------------------------------------------------------------ //// Copyright (c) Microsoft Corporation. All rights reserved. // //[....] //[....] //[....] //----------------------------------------------------------------------------- namespace System.Data { using System; using System.Diagnostics; using System.Collections; using System.ComponentModel; ////// ConstraintEnumerator is an object for enumerating all constraints in a DataSet /// internal class ConstraintEnumerator { System.Collections.IEnumerator tables; System.Collections.IEnumerator constraints; Constraint currentObject; public ConstraintEnumerator(DataSet dataSet) { tables = (dataSet != null) ? dataSet.Tables.GetEnumerator() : null; currentObject = null; } public bool GetNext() { Constraint candidate; currentObject = null; while (tables != null) { if (constraints == null) { if (!tables.MoveNext()) { tables = null; return false; } constraints = ((DataTable)tables.Current).Constraints.GetEnumerator(); } if (!constraints.MoveNext()) { constraints = null; continue; } Debug.Assert(constraints.Current is Constraint, "ConstraintEnumerator, contains object which is not constraint"); candidate = (Constraint)constraints.Current; if (IsValidCandidate(candidate)) { currentObject = candidate; return true; } } return false; } public Constraint GetConstraint() { // If currentObject is null we are before first GetNext or after last GetNext--consumer is bad Debug.Assert (currentObject != null, "GetObject should never be called w/ null currentObject."); return currentObject; } protected virtual bool IsValidCandidate(Constraint constraint) { return true; } protected Constraint CurrentObject { get { return currentObject; } } } internal class ForeignKeyConstraintEnumerator : ConstraintEnumerator { public ForeignKeyConstraintEnumerator(DataSet dataSet) : base(dataSet) { } protected override bool IsValidCandidate(Constraint constraint) { return(constraint is ForeignKeyConstraint); } public ForeignKeyConstraint GetForeignKeyConstraint() { // If CurrentObject is null we are before first GetNext or after last GetNext--consumer is bad Debug.Assert (CurrentObject != null, "GetObject should never be called w/ null currentObject."); return(ForeignKeyConstraint)CurrentObject; } } internal sealed class ChildForeignKeyConstraintEnumerator : ForeignKeyConstraintEnumerator { // this is the table to do comparisons against DataTable table; public ChildForeignKeyConstraintEnumerator(DataSet dataSet, DataTable inTable) : base(dataSet) { this.table = inTable; } protected override bool IsValidCandidate(Constraint constraint) { return((constraint is ForeignKeyConstraint) && (((ForeignKeyConstraint)constraint).Table == table)); } } internal sealed class ParentForeignKeyConstraintEnumerator : ForeignKeyConstraintEnumerator { // this is the table to do comparisons against DataTable table; public ParentForeignKeyConstraintEnumerator(DataSet dataSet, DataTable inTable) : base(dataSet) { this.table = inTable; } protected override bool IsValidCandidate(Constraint constraint) { return((constraint is ForeignKeyConstraint) && (((ForeignKeyConstraint)constraint).RelatedTable == table)); } } } // File provided for Reference Use Only by Microsoft Corporation (c) 2007. //------------------------------------------------------------------------------ //// Copyright (c) Microsoft Corporation. All rights reserved. // //[....] //[....] //[....] //----------------------------------------------------------------------------- namespace System.Data { using System; using System.Diagnostics; using System.Collections; using System.ComponentModel; ////// ConstraintEnumerator is an object for enumerating all constraints in a DataSet /// internal class ConstraintEnumerator { System.Collections.IEnumerator tables; System.Collections.IEnumerator constraints; Constraint currentObject; public ConstraintEnumerator(DataSet dataSet) { tables = (dataSet != null) ? dataSet.Tables.GetEnumerator() : null; currentObject = null; } public bool GetNext() { Constraint candidate; currentObject = null; while (tables != null) { if (constraints == null) { if (!tables.MoveNext()) { tables = null; return false; } constraints = ((DataTable)tables.Current).Constraints.GetEnumerator(); } if (!constraints.MoveNext()) { constraints = null; continue; } Debug.Assert(constraints.Current is Constraint, "ConstraintEnumerator, contains object which is not constraint"); candidate = (Constraint)constraints.Current; if (IsValidCandidate(candidate)) { currentObject = candidate; return true; } } return false; } public Constraint GetConstraint() { // If currentObject is null we are before first GetNext or after last GetNext--consumer is bad Debug.Assert (currentObject != null, "GetObject should never be called w/ null currentObject."); return currentObject; } protected virtual bool IsValidCandidate(Constraint constraint) { return true; } protected Constraint CurrentObject { get { return currentObject; } } } internal class ForeignKeyConstraintEnumerator : ConstraintEnumerator { public ForeignKeyConstraintEnumerator(DataSet dataSet) : base(dataSet) { } protected override bool IsValidCandidate(Constraint constraint) { return(constraint is ForeignKeyConstraint); } public ForeignKeyConstraint GetForeignKeyConstraint() { // If CurrentObject is null we are before first GetNext or after last GetNext--consumer is bad Debug.Assert (CurrentObject != null, "GetObject should never be called w/ null currentObject."); return(ForeignKeyConstraint)CurrentObject; } } internal sealed class ChildForeignKeyConstraintEnumerator : ForeignKeyConstraintEnumerator { // this is the table to do comparisons against DataTable table; public ChildForeignKeyConstraintEnumerator(DataSet dataSet, DataTable inTable) : base(dataSet) { this.table = inTable; } protected override bool IsValidCandidate(Constraint constraint) { return((constraint is ForeignKeyConstraint) && (((ForeignKeyConstraint)constraint).Table == table)); } } internal sealed class ParentForeignKeyConstraintEnumerator : ForeignKeyConstraintEnumerator { // this is the table to do comparisons against DataTable table; public ParentForeignKeyConstraintEnumerator(DataSet dataSet, DataTable inTable) : base(dataSet) { this.table = inTable; } protected override bool IsValidCandidate(Constraint constraint) { return((constraint is ForeignKeyConstraint) && (((ForeignKeyConstraint)constraint).RelatedTable == table)); } } } // File provided for Reference Use Only by Microsoft Corporation (c) 2007.
Link Menu
![Network programming in C#, Network Programming in VB.NET, Network Programming in .NET](/images/book.jpg)
This book is available now!
Buy at Amazon US or
Buy at Amazon UK
- Operator.cs
- Rfc2898DeriveBytes.cs
- TabPanel.cs
- FileSystemEventArgs.cs
- QueryReaderSettings.cs
- TextBlock.cs
- InputBinder.cs
- TreeViewEvent.cs
- SurrogateEncoder.cs
- HttpCapabilitiesSectionHandler.cs
- XPathDocument.cs
- UIElementHelper.cs
- RoutedEvent.cs
- RenderingBiasValidation.cs
- ProviderConnectionPoint.cs
- VerificationException.cs
- Menu.cs
- Inflater.cs
- ByteStorage.cs
- MobileTemplatedControlDesigner.cs
- WebPartDesigner.cs
- SHA1.cs
- UIElementParagraph.cs
- SchemaTypeEmitter.cs
- DateTimePicker.cs
- Attributes.cs
- DesignTimeParseData.cs
- ScriptReferenceEventArgs.cs
- CodeDefaultValueExpression.cs
- TypedOperationInfo.cs
- Reference.cs
- SqlBinder.cs
- Stopwatch.cs
- XmlDocument.cs
- RoutedCommand.cs
- InstallHelper.cs
- ToolBar.cs
- GifBitmapEncoder.cs
- SystemException.cs
- XmlHelper.cs
- BitmapMetadataEnumerator.cs
- _DigestClient.cs
- COAUTHINFO.cs
- SafeArrayTypeMismatchException.cs
- Utility.cs
- ProtocolsConfigurationHandler.cs
- WindowsPrincipal.cs
- COM2ColorConverter.cs
- ButtonBase.cs
- LineProperties.cs
- FilteredReadOnlyMetadataCollection.cs
- AllMembershipCondition.cs
- DesignerValidatorAdapter.cs
- JapaneseLunisolarCalendar.cs
- Rotation3DAnimation.cs
- RijndaelCryptoServiceProvider.cs
- wmiprovider.cs
- PixelFormat.cs
- LocatorPartList.cs
- MessageQueueTransaction.cs
- SizeValueSerializer.cs
- MimeTypeMapper.cs
- ClaimTypeRequirement.cs
- BitArray.cs
- FixedSOMSemanticBox.cs
- _ConnectionGroup.cs
- NamespaceExpr.cs
- ComplexType.cs
- ServiceXNameTypeConverter.cs
- TableLayout.cs
- FlatButtonAppearance.cs
- LocalizableAttribute.cs
- DocumentViewerAutomationPeer.cs
- CodeGenerator.cs
- OutputCacheProfileCollection.cs
- CategoryNameCollection.cs
- TextDpi.cs
- SchemaImporterExtensionElementCollection.cs
- KoreanLunisolarCalendar.cs
- MetaDataInfo.cs
- HttpClientChannel.cs
- Rotation3DKeyFrameCollection.cs
- OdbcEnvironmentHandle.cs
- PriorityItem.cs
- handlecollector.cs
- UIntPtr.cs
- RegistryExceptionHelper.cs
- Rect3DValueSerializer.cs
- XmlHelper.cs
- ContainerControl.cs
- StorageModelBuildProvider.cs
- Compress.cs
- DataBoundLiteralControl.cs
- APCustomTypeDescriptor.cs
- ScriptComponentDescriptor.cs
- infer.cs
- NotImplementedException.cs
- PathGradientBrush.cs
- Debug.cs
- WindowsHyperlink.cs