Updates referencesource to .NET 4.7
[mono-project.git] / mcs / class / referencesource / System.Core / System / Linq / Parallel / Enumerables / ParallelEnumerableWrapper.cs
blob31d072f3b071abf8a82c98833e6647b11160e028
1 // ==++==
2 //
3 // Copyright (c) Microsoft Corporation. All rights reserved.
4 //
5 // ==--==
6 // =+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+
7 //
8 // ParallelEnumerableWrapper.cs
9 //
10 // <OWNER>Microsoft</OWNER>
12 // =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
14 using System.Collections;
15 using System.Collections.Generic;
16 using System.Diagnostics.Contracts;
18 namespace System.Linq.Parallel
20 /// <summary>
21 /// A simple implementation of the ParallelQuery{object} interface which wraps an
22 /// underlying IEnumerable, such that it can be used in parallel queries.
23 /// </summary>
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);
37 m_source = source;
40 internal override IEnumerator GetEnumeratorUntyped()
42 return m_source.GetEnumerator();
45 public override IEnumerator<object> GetEnumerator()
47 return new EnumerableWrapperWeakToStrong(m_source).GetEnumerator();
51 /// <summary>
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.
54 /// </summary>
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.
64 // Arguments:
65 // wrappedEnumerable - the underlying enumerable object being wrapped
67 // Notes:
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();