1
0
mirror of https://github.com/oliverbooth/X10D synced 2024-11-09 23:25:43 +00:00

(#14) Use clearer variable and param names

This commit is contained in:
Oliver Booth 2021-03-10 11:08:39 +00:00
parent 9f9a79fd1b
commit f0ee53befb

View File

@ -11,16 +11,16 @@ namespace X10D.EnumExtensions
/// Returns the next member defined in a specified enum.
/// </summary>
/// <typeparam name="T">The enum type.</typeparam>
/// <param name="src">The enum value which should be used as the starting point.</param>
/// <param name="source">The enum value which should be used as the starting point.</param>
/// <param name="wrap">
/// Optional. <see langword="true" /> if the final value of <typeparamref name="T" /> should wrap around to the first
/// value, or <see langword="false" /> otherwise. Defaults to <see langword="true" />.
/// </param>
/// <returns>
/// A value of <typeparamref name="T" /> that is considered to be the next value defined after
/// <paramref name="src" />.
/// <paramref name="source" />.
/// </returns>
public static T Next<T>(this T src, bool wrap = true)
public static T Next<T>(this T source, bool wrap = true)
where T : struct, Enum
{
if (!typeof(T).IsEnum)
@ -28,25 +28,25 @@ namespace X10D.EnumExtensions
throw new ArgumentException($"Argument {typeof(T).FullName} is not an enum");
}
var arr = (T[])Enum.GetValues(src.GetType());
var j = Array.IndexOf(arr, src) + 1;
return arr.Length == j ? arr[wrap ? 0 : j - 1] : arr[j];
var array = (T[])Enum.GetValues(source.GetType());
var index = Array.IndexOf(array, source) + 1;
return array.Length == index ? array[wrap ? 0 : index - 1] : array[index];
}
/// <summary>
/// Returns the previous member defined in a specified enum.
/// </summary>
/// <typeparam name="T">The enum type.</typeparam>
/// <param name="src">The enum value which should be used as the starting point.</param>
/// <param name="source">The enum value which should be used as the starting point.</param>
/// <param name="wrap">
/// Optional. <see langword="true" /> if the first value of <typeparamref name="T" /> should wrap around to the final
/// value, or <see langword="false" /> otherwise. Defaults to <see langword="true" />.
/// </param>
/// <returns>
/// A value of <typeparamref name="T" /> that is considered to be the previous value defined before
/// <paramref name="src" />.
/// <paramref name="source" />.
/// </returns>
public static T Previous<T>(this T src, bool wrap = true)
public static T Previous<T>(this T source, bool wrap = true)
where T : struct, Enum
{
if (!typeof(T).IsEnum)
@ -54,9 +54,9 @@ namespace X10D.EnumExtensions
throw new ArgumentException($"Argument {typeof(T).FullName} is not an Enum");
}
var arr = (T[])Enum.GetValues(src.GetType());
var j = Array.IndexOf(arr, src) - 1;
return j < 0 ? arr[wrap ? arr.Length - 1 : 0] : arr[j];
var array = (T[])Enum.GetValues(source.GetType());
var index = Array.IndexOf(array, source) - 1;
return index < 0 ? array[wrap ? array.Length - 1 : 0] : array[index];
}
}
}