Code:
/ 4.0 / 4.0 / DEVDIV_TFS / Dev10 / Releases / RTMRel / ndp / fx / src / Core / System / Linq / Parallel / Enumerables / ParallelQuery.cs / 1305376 / ParallelQuery.cs
// ==++== // // Copyright (c) Microsoft Corporation. All rights reserved. // // ==--== // =+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+ // // ParallelQuery.cs // //[....] // // ParallelQuery is an abstract class that represents a PLINQ query. // =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=- using System.Collections; using System.Collections.Generic; using System.Linq.Parallel; using System.Diagnostics.Contracts; namespace System.Linq { ////// Represents a parallel sequence. /// public class ParallelQuery : IEnumerable { // Settings that have been specified on the query so far. private QuerySettings m_specifiedSettings; internal ParallelQuery(QuerySettings specifiedSettings) { m_specifiedSettings = specifiedSettings; } //------------------------------------------------------------------------------------ // Settings that have been specified on the query so far. Some settings may still // be unspecified and will be replaced either by operators further in the query, // or filled in with defaults at query opening time. // internal QuerySettings SpecifiedQuerySettings { get { return m_specifiedSettings; } } //----------------------------------------------------------------------------------- // Returns a parallel enumerable that represents 'this' enumerable, with each element // casted to TCastTo. If some element is not of type TCastTo, InvalidCastException // is thrown. // internal virtual ParallelQueryCast () { Contract.Assert(false, "The derived class must override this method."); throw new NotSupportedException(); } //----------------------------------------------------------------------------------- // Returns a parallel enumerable that represents 'this' enumerable, with each element // casted to TCastTo. Elements that are not of type TCastTo will be left out from // the results. // internal virtual ParallelQuery OfType () { Contract.Assert(false, "The derived class must override this method."); throw new NotSupportedException(); } //----------------------------------------------------------------------------------- // Derived classes implement GetEnumeratorUntyped() instead of IEnumerable.GetEnumerator() // This is to avoid the method name conflict if the derived classes also implement // IEnumerable . // internal virtual IEnumerator GetEnumeratorUntyped() { Contract.Assert(false, "The derived class must override this method."); throw new NotSupportedException(); } /// /// Returns an enumerator that iterates through the sequence. /// ///An enumerator that iterates through the sequence. IEnumerator IEnumerable.GetEnumerator() { return GetEnumeratorUntyped(); } } ////// Represents a parallel sequence. /// public class ParallelQuery: ParallelQuery, IEnumerable { internal ParallelQuery(QuerySettings settings) : base(settings) { } internal sealed override ParallelQuery Cast () { return ParallelEnumerable.Select (this, elem => (TCastTo)(object)elem); } internal sealed override ParallelQuery OfType () { // @PERF: Currently defined in terms of other operators. This isn't the most performant // solution (because it results in two operators) but is simple to implement. return this .Where (elem => elem is TCastTo) .Select (elem => (TCastTo)(object)elem); } internal override IEnumerator GetEnumeratorUntyped() { return ((IEnumerable )this).GetEnumerator(); } /// /// Returns an enumerator that iterates through the sequence. /// ///An enumerator that iterates through the sequence. public virtual IEnumeratorGetEnumerator() { Contract.Assert(false, "The derived class must override this method."); throw new NotSupportedException(); } } } // File provided for Reference Use Only by Microsoft Corporation (c) 2007. // ==++== // // Copyright (c) Microsoft Corporation. All rights reserved. // // ==--== // =+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+ // // ParallelQuery.cs // // [....] // // ParallelQuery is an abstract class that represents a PLINQ query. // =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=- using System.Collections; using System.Collections.Generic; using System.Linq.Parallel; using System.Diagnostics.Contracts; namespace System.Linq { ////// Represents a parallel sequence. /// public class ParallelQuery : IEnumerable { // Settings that have been specified on the query so far. private QuerySettings m_specifiedSettings; internal ParallelQuery(QuerySettings specifiedSettings) { m_specifiedSettings = specifiedSettings; } //------------------------------------------------------------------------------------ // Settings that have been specified on the query so far. Some settings may still // be unspecified and will be replaced either by operators further in the query, // or filled in with defaults at query opening time. // internal QuerySettings SpecifiedQuerySettings { get { return m_specifiedSettings; } } //----------------------------------------------------------------------------------- // Returns a parallel enumerable that represents 'this' enumerable, with each element // casted to TCastTo. If some element is not of type TCastTo, InvalidCastException // is thrown. // internal virtual ParallelQueryCast () { Contract.Assert(false, "The derived class must override this method."); throw new NotSupportedException(); } //----------------------------------------------------------------------------------- // Returns a parallel enumerable that represents 'this' enumerable, with each element // casted to TCastTo. Elements that are not of type TCastTo will be left out from // the results. // internal virtual ParallelQuery OfType () { Contract.Assert(false, "The derived class must override this method."); throw new NotSupportedException(); } //----------------------------------------------------------------------------------- // Derived classes implement GetEnumeratorUntyped() instead of IEnumerable.GetEnumerator() // This is to avoid the method name conflict if the derived classes also implement // IEnumerable . // internal virtual IEnumerator GetEnumeratorUntyped() { Contract.Assert(false, "The derived class must override this method."); throw new NotSupportedException(); } /// /// Returns an enumerator that iterates through the sequence. /// ///An enumerator that iterates through the sequence. IEnumerator IEnumerable.GetEnumerator() { return GetEnumeratorUntyped(); } } ////// Represents a parallel sequence. /// public class ParallelQuery: ParallelQuery, IEnumerable { internal ParallelQuery(QuerySettings settings) : base(settings) { } internal sealed override ParallelQuery Cast () { return ParallelEnumerable.Select (this, elem => (TCastTo)(object)elem); } internal sealed override ParallelQuery OfType () { // @PERF: Currently defined in terms of other operators. This isn't the most performant // solution (because it results in two operators) but is simple to implement. return this .Where (elem => elem is TCastTo) .Select (elem => (TCastTo)(object)elem); } internal override IEnumerator GetEnumeratorUntyped() { return ((IEnumerable )this).GetEnumerator(); } /// /// Returns an enumerator that iterates through the sequence. /// ///An enumerator that iterates through the sequence. public virtual IEnumeratorGetEnumerator() { Contract.Assert(false, "The derived class must override this method."); throw new NotSupportedException(); } } } // 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
- GridSplitterAutomationPeer.cs
- DragStartedEventArgs.cs
- ExpressionBindings.cs
- AngleUtil.cs
- DataGridViewBindingCompleteEventArgs.cs
- ISessionStateStore.cs
- documentsequencetextpointer.cs
- Pair.cs
- XmlSchemaInfo.cs
- CellConstant.cs
- _AcceptOverlappedAsyncResult.cs
- SimplePropertyEntry.cs
- ObservableCollection.cs
- ConfigurationSettings.cs
- DocumentApplicationJournalEntry.cs
- CompositeControl.cs
- PrivilegedConfigurationManager.cs
- IndexedSelectQueryOperator.cs
- Utils.cs
- XmlDictionary.cs
- wgx_commands.cs
- ShapeTypeface.cs
- ValueChangedEventManager.cs
- CallContext.cs
- FontResourceCache.cs
- JapaneseLunisolarCalendar.cs
- CodeCommentStatement.cs
- DisplayNameAttribute.cs
- Comparer.cs
- selecteditemcollection.cs
- MediaScriptCommandRoutedEventArgs.cs
- X500Name.cs
- EditingCoordinator.cs
- FlowDocumentPage.cs
- SafeNativeMethods.cs
- XmlSchemaSimpleType.cs
- ColorIndependentAnimationStorage.cs
- DeferredTextReference.cs
- CollectionViewProxy.cs
- EncodedStreamFactory.cs
- RegexStringValidator.cs
- ObjectListItemCollection.cs
- IISUnsafeMethods.cs
- BlockCollection.cs
- XmlCharType.cs
- DBPropSet.cs
- Exception.cs
- ResXResourceReader.cs
- PromptEventArgs.cs
- ApplyImportsAction.cs
- IItemProperties.cs
- Misc.cs
- WebFaultClientMessageInspector.cs
- Resources.Designer.cs
- ManipulationStartingEventArgs.cs
- BitmapEffectDrawingContextWalker.cs
- DynamicMethod.cs
- EdmFunction.cs
- RestHandlerFactory.cs
- CompareInfo.cs
- _UriTypeConverter.cs
- IndexedEnumerable.cs
- DrawingContextWalker.cs
- ScrollItemPatternIdentifiers.cs
- Operators.cs
- RSAPKCS1KeyExchangeDeformatter.cs
- AspNetSynchronizationContext.cs
- NameValueConfigurationElement.cs
- Expression.cs
- MissingManifestResourceException.cs
- AutomationAttributeInfo.cs
- EditingCoordinator.cs
- DataGridTextBoxColumn.cs
- XsltConvert.cs
- ThreadSafeList.cs
- DbFunctionCommandTree.cs
- TimeSpan.cs
- StateManagedCollection.cs
- WindowsGraphicsWrapper.cs
- keycontainerpermission.cs
- CharEntityEncoderFallback.cs
- SystemPens.cs
- CFGGrammar.cs
- Lock.cs
- Sql8ConformanceChecker.cs
- COM2ComponentEditor.cs
- SqlServer2KCompatibilityAnnotation.cs
- TextServicesCompartmentContext.cs
- XamlWriter.cs
- RemotingException.cs
- ILGenerator.cs
- PolygonHotSpot.cs
- SplitterEvent.cs
- ErrorHandlerModule.cs
- XsltContext.cs
- SqlLiftIndependentRowExpressions.cs
- CfgArc.cs
- TextPattern.cs
- FormParameter.cs