Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions ShittyLINQ/ToHashSet.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
using System;
using System.Collections.Generic;
using System.Text;

namespace ShittyLINQ
{
public static partial class Extensions
{
/// <summary>
/// Returns a <see cref="HashSet{T}"/> of the source items.
/// </summary>
/// <typeparam name="T">Type of elements in source sequence.</typeparam>
/// <param name="source">Source sequence</param>
/// <returns>A hash set of the items in the sequence.</returns>
/// <exception cref="ArgumentNullException"><paramref name="source"/> is null</exception>
public static HashSet<T> ToHashSet<T>(this IEnumerable<T> source)
{
if (source == null) throw new ArgumentNullException();
return new HashSet<T>(source);
}
}
}
27 changes: 27 additions & 0 deletions ShittyLinqTests/ToHashSetTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
using Microsoft.VisualStudio.TestTools.UnitTesting;
using ShittyLINQ;
using ShittyTests.TestHelpers;
using System;
using System.Collections.Generic;

namespace ShittyLinqTests
{
[TestClass]
public class ToHashSetTests
{
[TestMethod]
public void ToHashSet_SequenceIsNull()
{
IEnumerable<int> nums = null;
Assert.ThrowsException<ArgumentNullException>(() => nums.ToHashSet());
}

[TestMethod]
public void ToHashSet_SequenceEquals()
{
var expected = new int[] { 0, 1, 2 };
var actual = expected.ToHashSet();
TestHelper.AssertCollectionsAreSame(expected, actual);
}
}
}