|
| 1 | +// Copyright 2020-2021 ONIXLabs |
| 2 | +// |
| 3 | +// Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | +// you may not use this file except in compliance with the License. |
| 5 | +// You may obtain a copy of the License at |
| 6 | +// |
| 7 | +// http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | +// |
| 9 | +// Unless required by applicable law or agreed to in writing, software |
| 10 | +// distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | +// See the License for the specific language governing permissions and |
| 13 | +// limitations under the License. |
| 14 | + |
| 15 | +using System; |
| 16 | +using System.Collections.Generic; |
| 17 | +using System.ComponentModel; |
| 18 | +using OnixLabs.Core.Linq; |
| 19 | + |
| 20 | +namespace OnixLabs.Core |
| 21 | +{ |
| 22 | + /// <summary> |
| 23 | + /// Provides extension methods for hash codes. |
| 24 | + /// </summary> |
| 25 | + [EditorBrowsable(EditorBrowsableState.Never)] |
| 26 | + public static class HashCodeExtensions |
| 27 | + { |
| 28 | + /// <summary> |
| 29 | + /// Adds an item to be hashed into a <see cref="HashCode"/> instance. |
| 30 | + /// </summary> |
| 31 | + /// <param name="hashCode">The <see cref="HashCode"/> which will receive the item to hash.</param> |
| 32 | + /// <param name="item">The item to hash into the <see cref="HashCode"/>.</param> |
| 33 | + /// <typeparam name="T">The underlying type of the item to hash.</typeparam> |
| 34 | + /// <returns>Returns the <see cref="HashCode"/> containing the added item.</returns> |
| 35 | + public static HashCode AddItem<T>(this HashCode hashCode, T item) |
| 36 | + { |
| 37 | + hashCode.Add(item); |
| 38 | + return hashCode; |
| 39 | + } |
| 40 | + |
| 41 | + /// <summary> |
| 42 | + /// Adds the items to be hashed into a <see cref="HashCode"/> instance. |
| 43 | + /// </summary> |
| 44 | + /// <param name="hashCode">The <see cref="HashCode"/> which will receive the items to hash.</param> |
| 45 | + /// <param name="items">The items to hash into the <see cref="HashCode"/>.</param> |
| 46 | + /// <typeparam name="T">The underlying type of the items to hash.</typeparam> |
| 47 | + /// <returns>Returns the <see cref="HashCode"/> containing the added items.</returns> |
| 48 | + public static HashCode AddItems<T>(this HashCode hashCode, IEnumerable<T> items) |
| 49 | + { |
| 50 | + items.ForEach(hashCode.Add); |
| 51 | + return hashCode; |
| 52 | + } |
| 53 | + } |
| 54 | +} |
0 commit comments