diff options
author | Alex Ghiondea <ghiondea.alexandru@microsoft.com> | 2015-12-23 23:17:35 +0300 |
---|---|---|
committer | Alex Ghiondea <ghiondea.alexandru@microsoft.com> | 2015-12-23 23:17:35 +0300 |
commit | 54a7e4b76dd58797a26fcdc727f0ba296f6c367d (patch) | |
tree | e386d328900e2fecd62d5562cb2546f35db927a2 /src/Common | |
parent | a4e8d45a352f5952912add6ee0391a4d8f201741 (diff) |
While porting the library I ended up updating quite a few projects to make sure they continue to work.
There were a couple of changes to the build system that are included in this change:
- The location of the tool to restore the packages is set to use dnu for now.
- When restoring packages for the internal build we need to actually pass the right parameters to the build of the depproj
There were a couple of places where we had some issues that I fixed while I was doing the port:
- The compiler gave error messages about some method out parameters not being assigned.
- There was one missing 'unsafe' modifier on an interop file
- I had to pull in a 'debug' method temporarily in the ret build. This was needed because the debug build of CoreLib currently does not build with the 'DEBUG' define.
[tfs-changeset: 1559864]
Diffstat (limited to 'src/Common')
3 files changed, 142 insertions, 0 deletions
diff --git a/src/Common/src/System/Collections/Generic/Empty.cs b/src/Common/src/System/Collections/Generic/Empty.cs new file mode 100644 index 000000000..b88c594b4 --- /dev/null +++ b/src/Common/src/System/Collections/Generic/Empty.cs @@ -0,0 +1,66 @@ +// Copyright (c) Microsoft. All rights reserved. +// Licensed under the MIT license. See LICENSE file in the project root for full license information. + +using System; +using System.Diagnostics; +using System.Collections; +using System.Collections.Generic; + +namespace System.Collections.Generic +{ + // + // Helper class to store reusable empty IEnumerables. + // + internal static class Empty<T> + { + // + // Returns a reusable empty IEnumerable<T> (that does not secretly implement more advanced collection interfaces.) + // + public static IEnumerable<T> Enumerable + { + get + { + return _enumerable; + } + } + + private sealed class EmptyEnumImpl : IEnumerable<T>, IEnumerator<T> + { + public IEnumerator<T> GetEnumerator() + { + return this; + } + + IEnumerator IEnumerable.GetEnumerator() + { + return this; + } + + public T Current + { + get { throw new InvalidOperationException(); } + } + + Object IEnumerator.Current + { + get { throw new InvalidOperationException(); } + } + + public bool MoveNext() + { + return false; + } + + public void Reset() + { + } + + public void Dispose() + { + } + } + + private static IEnumerable<T> _enumerable = new EmptyEnumImpl(); + } +} + diff --git a/src/Common/src/System/Collections/Generic/EnumerableExtensions.cs b/src/Common/src/System/Collections/Generic/EnumerableExtensions.cs new file mode 100644 index 000000000..851b8e90a --- /dev/null +++ b/src/Common/src/System/Collections/Generic/EnumerableExtensions.cs @@ -0,0 +1,22 @@ +// Copyright (c) Microsoft. All rights reserved. +// Licensed under the MIT license. See LICENSE file in the project root for full license information. + +using System; +using System.Diagnostics; +using System.Collections.Generic; + +namespace System.Collections.Generic +{ + internal static class EnumerableExtensions + { + // Used to prevent returning values out of IEnumerable<>-typed properties + // that an untrusted caller could cast back to array or List. + public static IEnumerable<T> AsNothingButIEnumerable<T>(this IEnumerable<T> en) + { + foreach (T t in en) + yield return t; + } + } +} + + diff --git a/src/Common/src/System/Linq/LowLevelEnumerable.cs b/src/Common/src/System/Linq/LowLevelEnumerable.cs new file mode 100644 index 000000000..2a360cb5b --- /dev/null +++ b/src/Common/src/System/Linq/LowLevelEnumerable.cs @@ -0,0 +1,54 @@ +// Copyright (c) Microsoft. All rights reserved. +// Licensed under the MIT license. See LICENSE file in the project root for full license information. + +using System; +using System.Diagnostics; +using System.Collections.Generic; + +namespace System.Linq +{ + internal static class LowLevelEnumerable + { + public static bool Any<T>(this IEnumerable<T> values) + { + Debug.Assert(values != null); + + IEnumerator<T> enumerator = values.GetEnumerator(); + return enumerator.MoveNext(); + } + + public static bool Any<T>(this IEnumerable<T> values, Func<T, bool> predicate) + { + Debug.Assert(values != null); + Debug.Assert(predicate != null); + foreach (T value in values) + { + if (predicate(value)) + return true; + } + return false; + } + + public static IEnumerable<U> Select<T, U>(this IEnumerable<T> values, Func<T, U> func) + { + Debug.Assert(values != null); + + foreach (T value in values) + { + yield return func(value); + } + } + + public static T[] ToArray<T>(this IEnumerable<T> values) + { + Debug.Assert(values != null); + + LowLevelList<T> list = new LowLevelList<T>(); + foreach (T value in values) + { + list.Add(value); + } + return list.ToArray(); + } + } +} |