Code:
/ Net / Net / 3.5.50727.3053 / DEVDIV / depot / DevDiv / releases / whidbey / netfxsp / 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

This book is available now!
Buy at Amazon US or
Buy at Amazon UK
- AppSettings.cs
- CmsUtils.cs
- SerializationStore.cs
- WSSecurityJan2004.cs
- DbConnectionClosed.cs
- DBSqlParserColumnCollection.cs
- TripleDESCryptoServiceProvider.cs
- CommandField.cs
- TreeNodeStyleCollection.cs
- ActivationArguments.cs
- ProfileGroupSettings.cs
- ListControl.cs
- CreateUserWizard.cs
- SessionPageStatePersister.cs
- Literal.cs
- ShaderEffect.cs
- DataPointer.cs
- HttpCookie.cs
- BasicHttpMessageSecurity.cs
- DirectoryNotFoundException.cs
- CodeAccessPermission.cs
- Empty.cs
- QuadraticBezierSegment.cs
- DataGridColumnHeaderAutomationPeer.cs
- ISessionStateStore.cs
- SqlFunctionAttribute.cs
- Trace.cs
- Command.cs
- SqlNodeAnnotation.cs
- DefaultTextStoreTextComposition.cs
- DeviceContexts.cs
- FigureParaClient.cs
- DefaultPerformanceCounters.cs
- WizardStepBase.cs
- ExpressionBindings.cs
- DrawingServices.cs
- Int64Converter.cs
- ErrorFormatter.cs
- Vector3DKeyFrameCollection.cs
- RangeValueProviderWrapper.cs
- XLinq.cs
- BasicViewGenerator.cs
- PlaceHolder.cs
- Thread.cs
- DragDrop.cs
- GrammarBuilderRuleRef.cs
- PhysicalAddress.cs
- UpdatePanelTrigger.cs
- GridViewColumnCollectionChangedEventArgs.cs
- SQLCharsStorage.cs
- WindowsScroll.cs
- ToolStripItemClickedEventArgs.cs
- EventPropertyMap.cs
- PrintPageEvent.cs
- StorageConditionPropertyMapping.cs
- RtfToXamlLexer.cs
- Delegate.cs
- SqlXmlStorage.cs
- CoreSwitches.cs
- RelationshipType.cs
- NamespaceEmitter.cs
- EdmToObjectNamespaceMap.cs
- ColorAnimation.cs
- FileDetails.cs
- ImageConverter.cs
- ExpressionReplacer.cs
- DataGridViewSelectedColumnCollection.cs
- MessageBox.cs
- HwndStylusInputProvider.cs
- CodeChecksumPragma.cs
- SendingRequestEventArgs.cs
- RSACryptoServiceProvider.cs
- StringStorage.cs
- DataErrorValidationRule.cs
- control.ime.cs
- StatusBarItem.cs
- MarginCollapsingState.cs
- RequestStatusBarUpdateEventArgs.cs
- TransformerTypeCollection.cs
- TimersDescriptionAttribute.cs
- BamlWriter.cs
- ZoneLinkButton.cs
- JapaneseLunisolarCalendar.cs
- ListDataHelper.cs
- KoreanCalendar.cs
- diagnosticsswitches.cs
- DictionarySectionHandler.cs
- InstanceDescriptor.cs
- HtmlAnchor.cs
- ISFTagAndGuidCache.cs
- _TLSstream.cs
- SpellerStatusTable.cs
- DefaultBindingPropertyAttribute.cs
- Site.cs
- SectionXmlInfo.cs
- TextUtf8RawTextWriter.cs
- BindingBase.cs
- TailPinnedEventArgs.cs
- CounterSample.cs
- UshortList2.cs