Skip to content
This repository has been archived by the owner on Jan 23, 2023. It is now read-only.

Commit

Permalink
Format LINQ code
Browse files Browse the repository at this point in the history
Almost entirely automated formatting of LINQ code, via VS refactorings (e.g. renaming fields to follow corefx naming guidelines), StyleCop rules (e.g. using braces in many more places), and CodeFormatter (e.g. inserting blank lines in various places, adding readonly in several places).
  • Loading branch information
stephentoub committed Feb 23, 2016
1 parent c657cc9 commit 83ebd71
Show file tree
Hide file tree
Showing 43 changed files with 3,415 additions and 903 deletions.
67 changes: 55 additions & 12 deletions src/System.Linq/src/System/Linq/Aggregate.cs
Expand Up @@ -2,7 +2,6 @@
// 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
Expand All @@ -11,33 +10,77 @@ 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");
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();
if (!e.MoveNext())
{
throw Error.NoElements();
}

TSource result = e.Current;
while (e.MoveNext()) result = func(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");
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);
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");
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);
foreach (TSource element in source)
{
result = func(result, element);
}

return resultSelector(result);
}
}
Expand Down
43 changes: 35 additions & 8 deletions src/System.Linq/src/System/Linq/AnyAll.cs
Expand Up @@ -2,7 +2,6 @@
// 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
Expand All @@ -11,7 +10,11 @@ public static partial class Enumerable
{
public static bool Any<TSource>(this IEnumerable<TSource> source)
{
if (source == null) throw Error.ArgumentNull("source");
if (source == null)
{
throw Error.ArgumentNull("source");
}

using (IEnumerator<TSource> e = source.GetEnumerator())
{
return e.MoveNext();
Expand All @@ -20,23 +23,47 @@ public static bool Any<TSource>(this IEnumerable<TSource> source)

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");
if (source == null)
{
throw Error.ArgumentNull("source");
}

if (predicate == null)
{
throw Error.ArgumentNull("predicate");
}

foreach (TSource element in source)
{
if (predicate(element)) return true;
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");
if (source == null)
{
throw Error.ArgumentNull("source");
}

if (predicate == null)
{
throw Error.ArgumentNull("predicate");
}

foreach (TSource element in source)
{
if (!predicate(element)) return false;
if (!predicate(element))
{
return false;
}
}

return true;
}
}
Expand Down

0 comments on commit 83ebd71

Please sign in to comment.