3 // Copyright (c) Microsoft Corporation. All rights reserved.
6 // =+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+
8 // ParallelEnumerableWrapper.cs
10 // <OWNER>Microsoft</OWNER>
12 // =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
14 using System
.Collections
;
15 using System
.Collections
.Generic
;
16 using System
.Diagnostics
.Contracts
;
18 namespace System
.Linq
.Parallel
21 /// A simple implementation of the ParallelQuery{object} interface which wraps an
22 /// underlying IEnumerable, such that it can be used in parallel queries.
24 internal class ParallelEnumerableWrapper
: ParallelQuery
<object>
27 private readonly IEnumerable m_source
; // The wrapped enumerable object.
29 //-----------------------------------------------------------------------------------
30 // Instantiates a new wrapper object.
33 internal ParallelEnumerableWrapper(Collections
.IEnumerable source
)
34 : base(QuerySettings
.Empty
)
36 Contract
.Assert(source
!= null);
40 internal override IEnumerator
GetEnumeratorUntyped()
42 return m_source
.GetEnumerator();
45 public override IEnumerator
<object> GetEnumerator()
47 return new EnumerableWrapperWeakToStrong(m_source
).GetEnumerator();
52 /// A simple implementation of the ParallelQuery{T} interface which wraps an
53 /// underlying IEnumerable{T}, such that it can be used in parallel queries.
55 /// <typeparam name="T"></typeparam>
56 internal class ParallelEnumerableWrapper
<T
> : ParallelQuery
<T
>
59 private readonly IEnumerable
<T
> m_wrappedEnumerable
; // The wrapped enumerable object.
61 //-----------------------------------------------------------------------------------
62 // Instantiates a new wrapper object.
65 // wrappedEnumerable - the underlying enumerable object being wrapped
68 // The analysisOptions and degreeOfParallelism settings are optional. Passing null
69 // indicates that the system defaults should be used instead.
72 internal ParallelEnumerableWrapper(IEnumerable
<T
> wrappedEnumerable
)
73 : base(QuerySettings
.Empty
)
75 Contract
.Assert(wrappedEnumerable
!= null, "wrappedEnumerable must not be null.");
77 m_wrappedEnumerable
= wrappedEnumerable
;
80 //-----------------------------------------------------------------------------------
81 // Retrieves the wrapped enumerable object.
84 internal IEnumerable
<T
> WrappedEnumerable
86 get { return m_wrappedEnumerable; }
89 //-----------------------------------------------------------------------------------
90 // Implementations of GetEnumerator that just delegate to the wrapped enumerable.
93 public override IEnumerator
<T
> GetEnumerator()
95 Contract
.Assert(m_wrappedEnumerable
!= null);
96 return m_wrappedEnumerable
.GetEnumerator();