Skip to content

Commit

Permalink
Refactor System.Linq
Browse files Browse the repository at this point in the history
Move classes into separate files.

Split Enumerable among several files.

Remove redundant references to generic types or namespaces.

Fixes #1149
  • Loading branch information
JonHanna committed Feb 11, 2016
1 parent 20d48f3 commit d242474
Show file tree
Hide file tree
Showing 43 changed files with 6,086 additions and 5,583 deletions.
43 changes: 42 additions & 1 deletion src/System.Linq/src/System.Linq.csproj
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.props))\dir.props" />
<PropertyGroup>
Expand Down Expand Up @@ -34,8 +34,49 @@
<Compile Include="$(CommonPath)\System\Diagnostics\CodeAnalysis\ExcludeFromCodeCoverageAttribute.cs">
<Link>System\Diagnostics\CodeAnalysis\ExcludeFromCodeCoverageAttribute.cs</Link>
</Compile>
<Compile Include="System\Linq\Aggregate.cs" />
<Compile Include="System\Linq\AnyAll.cs" />
<Compile Include="System\Linq\Average.cs" />
<Compile Include="System\Linq\Buffer.cs" />
<Compile Include="System\Linq\Cast.cs" />
<Compile Include="System\Linq\Concatenate.cs" />
<Compile Include="System\Linq\Contains.cs" />
<Compile Include="System\Linq\Count.cs" />
<Compile Include="System\Linq\DebugView.cs" />
<Compile Include="System\Linq\DefaultIfEmpty.cs" />
<Compile Include="System\Linq\Distinct.cs" />
<Compile Include="System\Linq\ElementAt.cs" />
<Compile Include="System\Linq\Enumerable.cs" />
<Compile Include="System\Linq\Errors.cs" />
<Compile Include="System\Linq\Except.cs" />
<Compile Include="System\Linq\First.cs" />
<Compile Include="System\Linq\Grouping.cs" />
<Compile Include="System\Linq\GroupJoin.cs" />
<Compile Include="System\Linq\Intersect.cs" />
<Compile Include="System\Linq\Iterator.cs" />
<Compile Include="System\Linq\Join.cs" />
<Compile Include="System\Linq\Last.cs" />
<Compile Include="System\Linq\Lookup.cs" />
<Compile Include="System\Linq\Max.cs" />
<Compile Include="System\Linq\Min.cs" />
<Compile Include="System\Linq\OrderBy.cs" />
<Compile Include="System\Linq\OrderedEnumerable.cs" />
<Compile Include="System\Linq\Partition.cs" />
<Compile Include="System\Linq\Range.cs" />
<Compile Include="System\Linq\Repeat.cs" />
<Compile Include="System\Linq\Reverse.cs" />
<Compile Include="System\Linq\Select.cs" />
<Compile Include="System\Linq\SelectMany.cs" />
<Compile Include="System\Linq\SequenceEqual.cs" />
<Compile Include="System\Linq\Set.cs" />
<Compile Include="System\Linq\Single.cs" />
<Compile Include="System\Linq\Skip.cs" />
<Compile Include="System\Linq\Sum.cs" />
<Compile Include="System\Linq\Take.cs" />
<Compile Include="System\Linq\ToCollection.cs" />
<Compile Include="System\Linq\Union.cs" />
<Compile Include="System\Linq\Where.cs" />
<Compile Include="System\Linq\Zip.cs" />
</ItemGroup>
<ItemGroup Condition="'$(TargetGroup)' == 'net462'">
<TargetingPackReference Include="mscorlib" />
Expand Down
44 changes: 44 additions & 0 deletions src/System.Linq/src/System/Linq/Aggregate.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.

using System;
using System.Collections.Generic;

namespace System.Linq
{
public static partial class Enumerable
{
public static TSource Aggregate<TSource>(this IEnumerable<TSource> source, Func<TSource, TSource, TSource> func)
{
if (source == null) throw Error.ArgumentNull("source");
if (func == null) throw Error.ArgumentNull("func");
using (IEnumerator<TSource> e = source.GetEnumerator())
{
if (!e.MoveNext()) throw Error.NoElements();
TSource result = e.Current;
while (e.MoveNext()) result = func(result, e.Current);
return result;
}
}

public static TAccumulate Aggregate<TSource, TAccumulate>(this IEnumerable<TSource> source, TAccumulate seed, Func<TAccumulate, TSource, TAccumulate> func)
{
if (source == null) throw Error.ArgumentNull("source");
if (func == null) throw Error.ArgumentNull("func");
TAccumulate result = seed;
foreach (TSource element in source) result = func(result, element);
return result;
}

public static TResult Aggregate<TSource, TAccumulate, TResult>(this IEnumerable<TSource> source, TAccumulate seed, Func<TAccumulate, TSource, TAccumulate> func, Func<TAccumulate, TResult> resultSelector)
{
if (source == null) throw Error.ArgumentNull("source");
if (func == null) throw Error.ArgumentNull("func");
if (resultSelector == null) throw Error.ArgumentNull("resultSelector");
TAccumulate result = seed;
foreach (TSource element in source) result = func(result, element);
return resultSelector(result);
}
}
}
43 changes: 43 additions & 0 deletions src/System.Linq/src/System/Linq/AnyAll.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.

using System;
using System.Collections.Generic;

namespace System.Linq
{
public static partial class Enumerable
{
public static bool Any<TSource>(this IEnumerable<TSource> source)
{
if (source == null) throw Error.ArgumentNull("source");
using (IEnumerator<TSource> e = source.GetEnumerator())
{
return e.MoveNext();
}
}

public static bool Any<TSource>(this IEnumerable<TSource> source, Func<TSource, bool> predicate)
{
if (source == null) throw Error.ArgumentNull("source");
if (predicate == null) throw Error.ArgumentNull("predicate");
foreach (TSource element in source)
{
if (predicate(element)) return true;
}
return false;
}

public static bool All<TSource>(this IEnumerable<TSource> source, Func<TSource, bool> predicate)
{
if (source == null) throw Error.ArgumentNull("source");
if (predicate == null) throw Error.ArgumentNull("predicate");
foreach (TSource element in source)
{
if (!predicate(element)) return false;
}
return true;
}
}
}
Loading

0 comments on commit d242474

Please sign in to comment.