Achieves 100% XML doc coverage on non-trivial types with CS1591 enforcement via Directory.Build.props. Coverage by project: - Butter: from 6.5% to 100% (DTOs, enums, MIME types) - Lactose: from ~28% to 100% (controllers, services, repos, jobs, models) - MilkStream.Client: from ~29% to 100% (all frontend services) Uses <inheritdoc /> on repository implementations (interfaces already documented) and full <summary>/<param>/<returns> tags elsewhere. Enums include member-level docs.
48 lines
1.7 KiB
C#
48 lines
1.7 KiB
C#
using System.Collections;
|
|
using System.Runtime.CompilerServices;
|
|
|
|
namespace Lactose.Utils;
|
|
|
|
/// <summary>
|
|
/// Provides extension methods for IEnumerable.
|
|
/// </summary>
|
|
public static class EnumerableExtensions {
|
|
/// <summary>
|
|
/// Executes an action for each element in the sequence.
|
|
/// </summary>
|
|
/// <param name="source">The source sequence.</param>
|
|
/// <param name="action">The action to execute for each element.</param>
|
|
/// <typeparam name="TSource">The type of elements in the sequence.</typeparam>
|
|
public static void ForEach<TSource>(this IEnumerable<TSource> source, Action<TSource> action) {
|
|
foreach (var item in source) {
|
|
action(item);
|
|
}
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// Provides extension methods for perceptual hash (ulong/BitArray) conversions.
|
|
/// </summary>
|
|
public static class HashExtensions {
|
|
/// <summary>
|
|
/// Converts a ulong hash value to a BitArray.
|
|
/// </summary>
|
|
/// <param name="hash">The hash value.</param>
|
|
/// <returns>A 64-bit BitArray.</returns>
|
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
|
public static BitArray ToBitArray(this ulong hash) => new BitArray(BitConverter.GetBytes(hash));
|
|
|
|
/// <summary>
|
|
/// Converts a BitArray hash to a ulong value.
|
|
/// </summary>
|
|
/// <param name="bits">The BitArray to convert (must be at most 64 bits).</param>
|
|
/// <returns>The ulong representation.</returns>
|
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
|
public static ulong ToUlong(this BitArray bits) {
|
|
if (bits.Length > 64) throw new ArgumentException("BitArray length must be at most 64 bits.");
|
|
var array = new byte[8];
|
|
bits.CopyTo(array, 0);
|
|
return BitConverter.ToUInt64(array, 0);
|
|
}
|
|
}
|