🔨 Use block bodies instead of expression bodies

This commit is contained in:
Oliver Booth 2019-11-19 15:15:32 +00:00
parent a67fd274fa
commit 75a37d44d4
No known key found for this signature in database
GPG Key ID: 0D7F2EF1C8D2B9C0
17 changed files with 524 additions and 262 deletions

View File

@ -21,8 +21,10 @@
/// </summary>
/// <param name="image">The image to convert.</param>
/// <returns>Returns an <see cref="Image"/>.</returns>
public static async Task<Image> ToSquareAsync(this Image image) =>
await Task.Run(image.ToSquare);
public static async Task<Image> ToSquareAsync(this Image image)
{
return await Task.Run(image.ToSquare);
}
/// <summary>
/// Asynchronously converts the image so that its aspect ratio is 1:1, surrounding any new area with
@ -31,8 +33,10 @@
/// <param name="image">The image to convert.</param>
/// <param name="size">The new size of the image, i.e. the value of both the width and height.</param>
/// <returns>Returns an <see cref="Image"/>.</returns>
public static async Task<Image> ToSquareAsync(this Image image, int size) =>
await Task.Run(() => image.ToSquare(size));
public static async Task<Image> ToSquareAsync(this Image image, int size)
{
return await Task.Run(() => image.ToSquare(size));
}
/// <summary>
/// Asynchronously converts the image so that its aspect ratio is 1:1, surrounding any new area with a
@ -42,8 +46,10 @@
/// <param name="size">The new size of the image, i.e. the value of both the width and height.</param>
/// <param name="background">The background color to fill.</param>
/// <returns>Returns an <see cref="Image"/>.</returns>
public static async Task<Image> ToSquareAsync(this Image image, int size, Color background) =>
await Task.Run(() => image.ToSquare(size, background));
public static async Task<Image> ToSquareAsync(this Image image, int size, Color background)
{
return await Task.Run(() => image.ToSquare(size, background));
}
/// <summary>
/// Asynchronously converts the image so that its aspect ratio is 1:1, surrounding any new area with a
@ -52,16 +58,20 @@
/// <param name="image">The image to convert.</param>
/// <param name="background">The background color to fill.</param>
/// <returns>Returns an <see cref="Image"/>.</returns>
public static async Task<Image> ToSquareAsync(this Image image, Color background) =>
await Task.Run(() => image.ToSquare(background));
public static async Task<Image> ToSquareAsync(this Image image, Color background)
{
return await Task.Run(() => image.ToSquare(background));
}
/// <summary>
/// Converts the image so that its aspect ratio is 1:1, surrounding any new area with transparency.
/// </summary>
/// <param name="image">The image to convert.</param>
/// <returns>Returns an <see cref="Image"/>.</returns>
public static Image ToSquare(this Image image) =>
image.ToSquare(Color.Transparent);
public static Image ToSquare(this Image image)
{
return image.ToSquare(Color.Transparent);
}
/// <summary>
/// Converts the image so that its aspect ratio is 1:1, surrounding any new area with transparency.
@ -69,8 +79,10 @@
/// <param name="image">The image to convert.</param>
/// <param name="size">The new size of the image, i.e. the value of both the width and height.</param>
/// <returns>Returns an <see cref="Image"/>.</returns>
public static Image ToSquare(this Image image, int size) =>
image.ToSquare(size, Color.Transparent);
public static Image ToSquare(this Image image, int size)
{
return image.ToSquare(size, Color.Transparent);
}
/// <summary>
/// Converts the image so that its aspect ratio is 1:1, surrounding any new area with a specified background
@ -117,8 +129,10 @@
/// <param name="width">The new width.</param>
/// <param name="height">The new height.</param>
/// <returns>Returns a new <see cref="Image"/>.</returns>
public static async Task<Bitmap> ScaleAsync(this Image image, int width, int height) =>
await Task.Run(() => image.Scale(width, height));
public static async Task<Bitmap> ScaleAsync(this Image image, int width, int height)
{
return await Task.Run(() => image.Scale(width, height));
}
/// <summary>
/// Asynchronously scales the image.
@ -126,8 +140,10 @@
/// <param name="image">The image to scale.</param>
/// <param name="factor">The scale factor.</param>
/// <returns>Returns a new <see cref="Image"/>.</returns>
public static async Task<Bitmap> ScaleAsync(this Image image, float factor) =>
await Task.Run(() => image.Scale(factor));
public static async Task<Bitmap> ScaleAsync(this Image image, float factor)
{
return await Task.Run(() => image.Scale(factor));
}
/// <summary>
/// Scales the image.
@ -135,8 +151,10 @@
/// <param name="image">The image to scale.</param>
/// <param name="factor">The scale factor.</param>
/// <returns>Returns a new <see cref="Image"/>.</returns>
public static Bitmap Scale(this Image image, float factor) =>
image.Scale((int)(image.Width * factor), (int)(image.Height * factor));
public static Bitmap Scale(this Image image, float factor)
{
return image.Scale((int) (image.Width * factor), (int) (image.Height * factor));
}
/// <summary>
/// Scales the image.

View File

@ -32,31 +32,39 @@
/// <param name="v">The vector to round.</param>
/// <param name="nearest">The nearest value.</param>
/// <returns>Returns a <see cref="Vector3"/> containing the rounded values.</returns>
public static Vector3 Round(this Vector3 v, int nearest = 1) =>
new Vector3(v.x.Round(nearest), v.y.Round(nearest), v.z.Round(nearest));
public static Vector3 Round(this Vector3 v, int nearest = 1)
{
return new Vector3(v.x.Round(nearest), v.y.Round(nearest), v.z.Round(nearest));
}
/// <summary>
/// Inverts the X component of a vector.
/// </summary>
/// <param name="v">The vector to evaluate.</param>
/// <returns>Returns a <see cref="Vector3"/> whose values are (-X, Y, Z).</returns>
public static Vector3 InvertX(this Vector3 v) =>
new Vector3(-v.x, v.y, v.z);
public static Vector3 InvertX(this Vector3 v)
{
return new Vector3(-v.x, v.y, v.z);
}
/// <summary>
/// Inverts the Y component of a vector.
/// </summary>
/// <param name="v">The vector to evaluate.</param>
/// <returns>Returns a <see cref="Vector3"/> whose values are (X, -Y, Z).</returns>
public static Vector3 InvertY(this Vector3 v) =>
new Vector3(v.x, -v.y, v.z);
public static Vector3 InvertY(this Vector3 v)
{
return new Vector3(v.x, -v.y, v.z);
}
/// <summary>
/// Inverts the Z component of a vector.
/// </summary>
/// <param name="v">The vector to evaluate.</param>
/// <returns>Returns a <see cref="Vector3"/> whose values are (X, Y, -Z).</returns>
public static Vector3 InvertZ(this Vector3 v) =>
new Vector3(v.x, v.y, -v.z);
public static Vector3 InvertZ(this Vector3 v)
{
return new Vector3(v.x, v.y, -v.z);
}
}
}

View File

@ -16,7 +16,9 @@
/// </summary>
/// <param name="value">The boolean.</param>
/// <returns>Returns 1 if <paramref name="value"/> is <see langword="true"/>, 0 otherwise.</returns>
public static int ToInt32(this bool value) =>
value ? 1 : 0;
public static int ToInt32(this bool value)
{
return value ? 1 : 0;
}
}
}

View File

@ -19,56 +19,70 @@
/// </summary>
/// <param name="bytes">The bytes to get.</param>
/// <returns>Returns a <see cref="String"/>.</returns>
public static string AsString(this IEnumerable<byte> bytes) =>
BitConverter.ToString(bytes.ToArray());
public static string AsString(this IEnumerable<byte> bytes)
{
return BitConverter.ToString(bytes.ToArray());
}
/// <summary>
/// Converts the <see cref="Byte"/>[] to an <see cref="Int16"/>.
/// </summary>
/// <param name="bytes">The bytes to convert.</param>
/// <returns>Returns an <see cref="Int16"/>.</returns>
public static short GetInt16(this IEnumerable<byte> bytes) =>
BitConverter.ToInt16(bytes.ToArray(), 0);
public static short GetInt16(this IEnumerable<byte> bytes)
{
return BitConverter.ToInt16(bytes.ToArray(), 0);
}
/// <summary>
/// Converts the <see cref="Byte"/>[] to an <see cref="Int32"/>.
/// </summary>
/// <param name="bytes">The bytes to convert.</param>
/// <returns>Returns an <see cref="Int32"/>.</returns>
public static int GetInt32(this IEnumerable<byte> bytes) =>
BitConverter.ToInt32(bytes.ToArray(), 0);
public static int GetInt32(this IEnumerable<byte> bytes)
{
return BitConverter.ToInt32(bytes.ToArray(), 0);
}
/// <summary>
/// Converts the <see cref="Byte"/>[] to an <see cref="Int64"/>.
/// </summary>
/// <param name="bytes">The bytes to convert.</param>
/// <returns>Returns an <see cref="Int64"/>.</returns>
public static long GetInt64(this IEnumerable<byte> bytes) =>
BitConverter.ToInt64(bytes.ToArray(), 0);
public static long GetInt64(this IEnumerable<byte> bytes)
{
return BitConverter.ToInt64(bytes.ToArray(), 0);
}
/// <summary>
/// Converts the <see cref="Byte"/>[] to a <see cref="UInt16"/>.
/// </summary>
/// <param name="bytes">The bytes to convert.</param>
/// <returns>Returns an <see cref="UInt16"/>.</returns>
public static ushort GetUInt16(this IEnumerable<byte> bytes) =>
BitConverter.ToUInt16(bytes.ToArray(), 0);
public static ushort GetUInt16(this IEnumerable<byte> bytes)
{
return BitConverter.ToUInt16(bytes.ToArray(), 0);
}
/// <summary>
/// Converts the <see cref="Byte"/>[] to an <see cref="UInt32"/>.
/// </summary>
/// <param name="bytes">The bytes to convert.</param>
/// <returns>Returns an <see cref="UInt32"/>.</returns>
public static uint GetUInt32(this IEnumerable<byte> bytes) =>
BitConverter.ToUInt32(bytes.ToArray(), 0);
public static uint GetUInt32(this IEnumerable<byte> bytes)
{
return BitConverter.ToUInt32(bytes.ToArray(), 0);
}
/// <summary>
/// Converts the <see cref="Byte"/>[] to an <see cref="UInt64"/>.
/// </summary>
/// <param name="bytes">The bytes to convert.</param>
/// <returns>Returns an <see cref="UInt64"/>.</returns>
public static ulong GetUInt64(this IEnumerable<byte> bytes) =>
BitConverter.ToUInt64(bytes.ToArray(), 0);
public static ulong GetUInt64(this IEnumerable<byte> bytes)
{
return BitConverter.ToUInt64(bytes.ToArray(), 0);
}
/// <summary>
/// Gets a <see cref="String"/> representing the value the <see cref="Byte"/>[] with
@ -76,8 +90,10 @@
/// </summary>
/// <param name="bytes">The bytes to convert.</param>
/// <returns>Returns a <see cref="String"/>.</returns>
public static string GetString(this IEnumerable<byte> bytes) =>
bytes.GetString(Encoding.UTF8);
public static string GetString(this IEnumerable<byte> bytes)
{
return bytes.GetString(Encoding.UTF8);
}
/// <summary>
/// Gets a <see cref="String"/> representing the value the <see cref="Byte"/>[] with the provided encoding.

View File

@ -18,7 +18,9 @@
/// <param name="count">The repeat count.</param>
/// <returns>Returns a <see cref="String"/> whose value is <paramref name="c"/> repeated
/// <paramref name="count"/> times.</returns>
public static string Repeat(this char c, int count) =>
new string(c, count);
public static string Repeat(this char c, int count)
{
return new string(c, count);
}
}
}

View File

@ -20,7 +20,9 @@
/// <param name="upper">The exclusive upper bound.</param>
/// <returns>Returns <see langword="true"/> if the value is between the bounds, <see langword="false"/>
/// otherwise.</returns>
public static bool Between<T>(this T actual, T lower, T upper) where T : IComparable<T> =>
actual.CompareTo(lower) > 0 && actual.CompareTo(upper) < 0;
public static bool Between<T>(this T actual, T lower, T upper) where T : IComparable<T>
{
return actual.CompareTo(lower) > 0 && actual.CompareTo(upper) < 0;
}
}
}

View File

@ -17,8 +17,10 @@
/// <typeparam name="T">The type to convert to.</typeparam>
/// <param name="obj">The object to convert.</param>
/// <returns>Returns the value converted to <see cref="T"/>.</returns>
public static T To<T>(this IConvertible obj) =>
(T)Convert.ChangeType(obj, typeof(T));
public static T To<T>(this IConvertible obj)
{
return (T) Convert.ChangeType(obj, typeof(T));
}
/// <summary>
/// Converts the object to another type, returning the default value on failure.

View File

@ -15,8 +15,10 @@
/// Calculates someone's age based on a date of birth.
/// </summary>
/// <param name="dateOfBirth">The date of birth.</param>
public static int Age(this DateTime dateOfBirth) =>
(int)(((DateTime.Today - TimeSpan.FromDays(1) - dateOfBirth.Date).TotalDays + 1) / 365.2425);
public static int Age(this DateTime dateOfBirth)
{
return (int) (((DateTime.Today - TimeSpan.FromDays(1) - dateOfBirth.Date).TotalDays + 1) / 365.2425);
}
/// <summary>
/// Gets a DateTime representing the first specified day in the current month
@ -40,8 +42,10 @@
/// Gets a <see cref="DateTime"/> representing the first day in the current month.
/// </summary>
/// <param name="current">The current date.</param>
public static DateTime FirstDayOfMonth(this DateTime current) =>
current.AddDays(1 - current.Day);
public static DateTime FirstDayOfMonth(this DateTime current)
{
return current.AddDays(1 - current.Day);
}
/// <summary>
/// Gets a <see cref="DateTime"/> representing the last day in the current month.
@ -72,8 +76,10 @@
/// Gets a <see cref="DateTime"/> representing midnight on the current date.
/// </summary>
/// <param name="current">The current date.</param>
public static DateTime Midnight(this DateTime current) =>
new DateTime(current.Year, current.Month, current.Day);
public static DateTime Midnight(this DateTime current)
{
return new DateTime(current.Year, current.Month, current.Day);
}
/// <summary>
/// Gets a <see cref="DateTime"/> representing the first date following the current date which falls on the
@ -98,8 +104,10 @@
/// Gets a <see cref="DateTime"/> representing noon on the current date.
/// </summary>
/// <param name="current">The current date.</param>
public static DateTime Noon(this DateTime current) =>
new DateTime(current.Year, current.Month, current.Day, 12, 0, 0);
public static DateTime Noon(this DateTime current)
{
return new DateTime(current.Year, current.Month, current.Day, 12, 0, 0);
}
/// <summary>
/// Sets the time of the current date with minute precision.
@ -107,8 +115,10 @@
/// <param name="current">The current date.</param>
/// <param name="hour">The hour.</param>
/// <param name="minute">The minute.</param>
public static DateTime SetTime(this DateTime current, int hour, int minute) =>
current.SetTime(hour, minute, 0, 0);
public static DateTime SetTime(this DateTime current, int hour, int minute)
{
return current.SetTime(hour, minute, 0, 0);
}
/// <summary>
/// Sets the time of the current date with second precision.
@ -118,8 +128,10 @@
/// <param name="minute">The minute.</param>
/// <param name="second">The second.</param>
/// <returns></returns>
public static DateTime SetTime(this DateTime current, int hour, int minute, int second) =>
current.SetTime(hour, minute, second, 0);
public static DateTime SetTime(this DateTime current, int hour, int minute, int second)
{
return current.SetTime(hour, minute, second, 0);
}
/// <summary>
/// Sets the time of the current date with millisecond precision.
@ -129,8 +141,10 @@
/// <param name="minute">The minute.</param>
/// <param name="second">The second.</param>
/// <param name="millisecond">The millisecond.</param>
public static DateTime SetTime(this DateTime current, int hour, int minute, int second, int millisecond) =>
new DateTime(current.Year, current.Month, current.Day, hour, minute, second, millisecond);
public static DateTime SetTime(this DateTime current, int hour, int minute, int second, int millisecond)
{
return new DateTime(current.Year, current.Month, current.Day, hour, minute, second, millisecond);
}
/// <summary>
/// Converts the <see cref="DateTime"/> to a Unix timestamp.
@ -151,7 +165,9 @@
/// <param name="date">The <see cref="DateTime"/> to copy.</param>
/// <param name="year">The year to set.</param>
/// <returns>Returns a <see cref="DateTime"/>.</returns>
public static DateTime WithYear(this DateTime date, int year) =>
new DateTime(year, date.Month, date.Day, date.Hour, date.Minute, date.Second, date.Millisecond);
public static DateTime WithYear(this DateTime date, int year)
{
return new DateTime(year, date.Month, date.Day, date.Hour, date.Minute, date.Second, date.Millisecond);
}
}
}

View File

@ -20,32 +20,40 @@
/// <returns>Returns <paramref name="max"/> if <paramref name="value"/> is greater than it,
/// <paramref name="min"/> if <paramref name="value"/> is less than it,
/// or <paramref name="value"/> itself otherwise.</returns>
public static double Clamp(this double value, double min, double max) =>
Math.Min(Math.Max(value, min), max);
public static double Clamp(this double value, double min, double max)
{
return Math.Min(Math.Max(value, min), max);
}
/// <summary>
/// Converts an angle from degrees to radians.
/// </summary>
/// <param name="angle">The angle in degrees.</param>
/// <returns>Returns <paramref name="angle"/> in radians.</returns>
public static double DegreesToRadians(this double angle) =>
Math.PI * angle / 180.0;
public static double DegreesToRadians(this double angle)
{
return Math.PI * angle / 180.0;
}
/// <summary>
/// Converts the <see cref="Double"/> to a <see cref="Byte"/>[].
/// </summary>
/// <param name="number">The number to convert.</param>
/// <returns>Returns a <see cref="Byte"/>[].</returns>
public static byte[] GetBytes(this double number) =>
BitConverter.GetBytes(number);
public static byte[] GetBytes(this double number)
{
return BitConverter.GetBytes(number);
}
/// <summary>
/// Converts an angle from radians to degrees.
/// </summary>
/// <param name="angle">The angle in radians.</param>
/// <returns>Returns <paramref name="angle"/> in degrees.</returns>
public static double RadiansToDegrees(this double angle) =>
angle * (180.0 / Math.PI);
public static double RadiansToDegrees(this double angle)
{
return angle * (180.0 / Math.PI);
}
/// <summary>
/// Rounds to the nearest value.
@ -53,7 +61,9 @@
/// <param name="v">The value to round.</param>
/// <param name="nearest">The nearest value.</param>
/// <returns>Returns the rounded value.</returns>
public static double Round(this double v, int nearest = 1) =>
Math.Round(v / nearest) * nearest;
public static double Round(this double v, int nearest = 1)
{
return Math.Round(v / nearest) * nearest;
}
}
}

View File

@ -18,25 +18,29 @@
/// <param name="endPoint">The endpoint whose hostname to get.</param>
/// <returns>Returns a <see cref="String"/> representing the hostname, which may be an IP or a DNS, or empty
/// string on failure.</returns>
public static string GetHost(this EndPoint endPoint) =>
endPoint switch
public static string GetHost(this EndPoint endPoint)
{
return endPoint switch
{
IPEndPoint ip => ip.Address.ToString(),
DnsEndPoint dns => dns.Host,
_ => String.Empty
};
}
/// <summary>
/// Gets the endpoint port.
/// </summary>
/// <param name="endPoint">The endpoint whose port to get.</param>
/// <returns>Returns an <see cref="Int32"/> representing the port, or 0 on failure.</returns>
public static int GetPort(this EndPoint endPoint) =>
endPoint switch
public static int GetPort(this EndPoint endPoint)
{
return endPoint switch
{
IPEndPoint ip => ip.Port,
DnsEndPoint dns => dns.Port,
_ => 0
};
}
}
}

View File

@ -15,41 +15,65 @@
// TODO change
public static TimeSpan Days(this ushort number) =>
TimeSpan.FromDays(number);
public static TimeSpan Days(this ushort number)
{
return TimeSpan.FromDays(number);
}
public static TimeSpan Hours(this ushort number) =>
TimeSpan.FromHours(number);
public static TimeSpan Hours(this ushort number)
{
return TimeSpan.FromHours(number);
}
public static TimeSpan Milliseconds(this ushort number) =>
TimeSpan.FromSeconds(number);
public static TimeSpan Milliseconds(this ushort number)
{
return TimeSpan.FromSeconds(number);
}
public static TimeSpan Minutes(this ushort number) =>
TimeSpan.FromMinutes(number);
public static TimeSpan Minutes(this ushort number)
{
return TimeSpan.FromMinutes(number);
}
public static TimeSpan Seconds(this ushort number) =>
TimeSpan.FromSeconds(number);
public static TimeSpan Seconds(this ushort number)
{
return TimeSpan.FromSeconds(number);
}
public static TimeSpan Ticks(this ushort number) =>
TimeSpan.FromTicks(number);
public static TimeSpan Ticks(this ushort number)
{
return TimeSpan.FromTicks(number);
}
public static TimeSpan Days(this short number) =>
TimeSpan.FromDays(number);
public static TimeSpan Days(this short number)
{
return TimeSpan.FromDays(number);
}
public static TimeSpan Hours(this short number) =>
TimeSpan.FromHours(number);
public static TimeSpan Hours(this short number)
{
return TimeSpan.FromHours(number);
}
public static TimeSpan Milliseconds(this short number) =>
TimeSpan.FromSeconds(number);
public static TimeSpan Milliseconds(this short number)
{
return TimeSpan.FromSeconds(number);
}
public static TimeSpan Minutes(this short number) =>
TimeSpan.FromMinutes(number);
public static TimeSpan Minutes(this short number)
{
return TimeSpan.FromMinutes(number);
}
public static TimeSpan Seconds(this short number) =>
TimeSpan.FromSeconds(number);
public static TimeSpan Seconds(this short number)
{
return TimeSpan.FromSeconds(number);
}
public static TimeSpan Ticks(this short number) =>
TimeSpan.FromTicks(number);
public static TimeSpan Ticks(this short number)
{
return TimeSpan.FromTicks(number);
}
#endregion
@ -62,8 +86,10 @@
/// <returns>Returns <paramref name="max"/> if <paramref name="value"/> is greater than it,
/// <paramref name="min"/> if <paramref name="value"/> is less than it,
/// or <paramref name="value"/> itself otherwise.</returns>
public static short Clamp(this short value, short min, short max) =>
Math.Min(Math.Max(value, min), max);
public static short Clamp(this short value, short min, short max)
{
return Math.Min(Math.Max(value, min), max);
}
/// <summary>
/// Clamps a value between a minimum and a maximum value.
@ -74,8 +100,10 @@
/// <returns>Returns <paramref name="max"/> if <paramref name="value"/> is greater than it,
/// <paramref name="min"/> if <paramref name="value"/> is less than it,
/// or <paramref name="value"/> itself otherwise.</returns>
public static ushort Clamp(this ushort value, ushort min, ushort max) =>
Math.Min(Math.Max(value, min), max);
public static ushort Clamp(this ushort value, ushort min, ushort max)
{
return Math.Min(Math.Max(value, min), max);
}
/// <summary>
/// Converts the <see cref="Int16"/> to a <see cref="DateTime"/> treating it as a Unix timestamp.
@ -85,24 +113,30 @@
/// to <see langword="false"/>..</param>
/// <returns>Returns a <see cref="DateTime"/> representing <paramref name="timestamp"/> seconds since the Unix
/// epoch.</returns>
public static DateTime FromUnixTimestamp(this short timestamp, bool isMillis = false) =>
((long)timestamp).FromUnixTimestamp(isMillis);
public static DateTime FromUnixTimestamp(this short timestamp, bool isMillis = false)
{
return ((long) timestamp).FromUnixTimestamp(isMillis);
}
/// <summary>
/// Converts the <see cref="UInt16"/> to a <see cref="Byte"/>[].
/// </summary>
/// <param name="number">The number to convert.</param>
/// <returns>Returns a <see cref="Byte"/>[].</returns>
public static byte[] GetBytes(this ushort number) =>
BitConverter.GetBytes(number);
public static byte[] GetBytes(this ushort number)
{
return BitConverter.GetBytes(number);
}
/// <summary>
/// Converts the <see cref="Int16"/> to a <see cref="Byte"/>[].
/// </summary>
/// <param name="number">The number to convert.</param>
/// <returns>Returns a <see cref="Byte"/>[].</returns>
public static byte[] GetBytes(this short number) =>
BitConverter.GetBytes(number);
public static byte[] GetBytes(this short number)
{
return BitConverter.GetBytes(number);
}
/// <summary>
/// Determines if the <see cref="Int16"/> is a prime number.
@ -110,8 +144,10 @@
/// <param name="number">The number.</param>
/// <returns>Returns <see langword="true"/> if <paramref name="number"/> is prime, <see langword="false"/>
/// otherwise.</returns>
public static bool IsPrime(this short number) =>
((long)number).IsPrime();
public static bool IsPrime(this short number)
{
return ((long) number).IsPrime();
}
/// <summary>
/// Gets an boolean value that represents this integer.
@ -119,8 +155,10 @@
/// <param name="value">The integer.</param>
/// <returns>Returns <see langword="false"/> if <paramref name="value"/> is 0,
/// <see langword="true"/> otherwise.</returns>
public static bool ToBoolean(this short value) =>
((long)value).ToBoolean();
public static bool ToBoolean(this short value)
{
return ((long) value).ToBoolean();
}
/// <summary>
/// Gets an boolean value that represents this integer.
@ -128,7 +166,9 @@
/// <param name="value">The integer.</param>
/// <returns>Returns <see langword="false"/> if <paramref name="value"/> is 0,
/// <see langword="true"/> otherwise.</returns>
public static bool ToBoolean(this ushort value) =>
((ulong)value).ToBoolean();
public static bool ToBoolean(this ushort value)
{
return ((ulong) value).ToBoolean();
}
}
}

View File

@ -21,8 +21,10 @@
/// <param name="hour">The hour.</param>
/// <param name="minute">The minute.</param>
/// <param name="second">The second.</param>
public static DateTime January(this int day, int year, int hour = 0, int minute = 0, int second = 0) =>
new DateTime(year, 1, day, hour, minute, second);
public static DateTime January(this int day, int year, int hour = 0, int minute = 0, int second = 0)
{
return new DateTime(year, 1, day, hour, minute, second);
}
/// <summary>
/// Returns a <see cref="DateTime"/> where the month is February.
@ -32,8 +34,10 @@
/// <param name="hour">The hour.</param>
/// <param name="minute">The minute.</param>
/// <param name="second">The second.</param>
public static DateTime February(this int day, int year, int hour = 0, int minute = 0, int second = 0) =>
new DateTime(year, 2, day, hour, minute, second);
public static DateTime February(this int day, int year, int hour = 0, int minute = 0, int second = 0)
{
return new DateTime(year, 2, day, hour, minute, second);
}
/// <summary>
/// Returns a <see cref="DateTime"/> where the month is March.
@ -43,8 +47,10 @@
/// <param name="hour">The hour.</param>
/// <param name="minute">The minute.</param>
/// <param name="second">The second.</param>
public static DateTime March(this int day, int year, int hour = 0, int minute = 0, int second = 0) =>
new DateTime(year, 3, day, hour, minute, second);
public static DateTime March(this int day, int year, int hour = 0, int minute = 0, int second = 0)
{
return new DateTime(year, 3, day, hour, minute, second);
}
/// <summary>
/// Returns a <see cref="DateTime"/> where the month is April.
@ -54,8 +60,10 @@
/// <param name="hour">The hour.</param>
/// <param name="minute">The minute.</param>
/// <param name="second">The second.</param>
public static DateTime April(this int day, int year, int hour = 0, int minute = 0, int second = 0) =>
new DateTime(year, 4, day, hour, minute, second);
public static DateTime April(this int day, int year, int hour = 0, int minute = 0, int second = 0)
{
return new DateTime(year, 4, day, hour, minute, second);
}
/// <summary>
/// Returns a <see cref="DateTime"/> where the month is May.
@ -65,8 +73,10 @@
/// <param name="hour">The hour.</param>
/// <param name="minute">The minute.</param>
/// <param name="second">The second.</param>
public static DateTime May(this int day, int year, int hour = 0, int minute = 0, int second = 0) =>
new DateTime(year, 5, day, hour, minute, second);
public static DateTime May(this int day, int year, int hour = 0, int minute = 0, int second = 0)
{
return new DateTime(year, 5, day, hour, minute, second);
}
/// <summary>
/// Returns a <see cref="DateTime"/> where the month is June.
@ -76,8 +86,10 @@
/// <param name="hour">The hour.</param>
/// <param name="minute">The minute.</param>
/// <param name="second">The second.</param>
public static DateTime June(this int day, int year, int hour = 0, int minute = 0, int second = 0) =>
new DateTime(year, 6, day, hour, minute, second);
public static DateTime June(this int day, int year, int hour = 0, int minute = 0, int second = 0)
{
return new DateTime(year, 6, day, hour, minute, second);
}
/// <summary>
/// Returns a <see cref="DateTime"/> where the month is July.
@ -87,8 +99,10 @@
/// <param name="hour">The hour.</param>
/// <param name="minute">The minute.</param>
/// <param name="second">The second.</param>
public static DateTime July(this int day, int year, int hour = 0, int minute = 0, int second = 0) =>
new DateTime(year, 7, day, hour, minute, second);
public static DateTime July(this int day, int year, int hour = 0, int minute = 0, int second = 0)
{
return new DateTime(year, 7, day, hour, minute, second);
}
/// <summary>
/// Returns a <see cref="DateTime"/> where the month is August.
@ -98,8 +112,10 @@
/// <param name="hour">The hour.</param>
/// <param name="minute">The minute.</param>
/// <param name="second">The second.</param>
public static DateTime August(this int day, int year, int hour = 0, int minute = 0, int second = 0) =>
new DateTime(year, 8, day, hour, minute, second);
public static DateTime August(this int day, int year, int hour = 0, int minute = 0, int second = 0)
{
return new DateTime(year, 8, day, hour, minute, second);
}
/// <summary>
/// Returns a <see cref="DateTime"/> where the month is September.
@ -109,8 +125,10 @@
/// <param name="hour">The hour.</param>
/// <param name="minute">The minute.</param>
/// <param name="second">The second.</param>
public static DateTime September(this int day, int year, int hour = 0, int minute = 0, int second = 0) =>
new DateTime(year, 9, day, hour, minute, second);
public static DateTime September(this int day, int year, int hour = 0, int minute = 0, int second = 0)
{
return new DateTime(year, 9, day, hour, minute, second);
}
/// <summary>
/// Returns a <see cref="DateTime"/> where the month is October.
@ -120,8 +138,10 @@
/// <param name="hour">The hour.</param>
/// <param name="minute">The minute.</param>
/// <param name="second">The second.</param>
public static DateTime October(this int day, int year, int hour = 0, int minute = 0, int second = 0) =>
new DateTime(year, 10, day, hour, minute, second);
public static DateTime October(this int day, int year, int hour = 0, int minute = 0, int second = 0)
{
return new DateTime(year, 10, day, hour, minute, second);
}
/// <summary>
/// Returns a <see cref="DateTime"/> where the month is November.
@ -131,8 +151,10 @@
/// <param name="hour">The hour.</param>
/// <param name="minute">The minute.</param>
/// <param name="second">The second.</param>
public static DateTime November(this int day, int year, int hour = 0, int minute = 0, int second = 0) =>
new DateTime(year, 11, day, hour, minute, second);
public static DateTime November(this int day, int year, int hour = 0, int minute = 0, int second = 0)
{
return new DateTime(year, 11, day, hour, minute, second);
}
/// <summary>
/// Returns a <see cref="DateTime"/> where the month is December.
@ -142,8 +164,10 @@
/// <param name="hour">The hour.</param>
/// <param name="minute">The minute.</param>
/// <param name="second">The second.</param>
public static DateTime December(this int day, int year, int hour = 0, int minute = 0, int second = 0) =>
new DateTime(year, 12, day, hour, minute, second);
public static DateTime December(this int day, int year, int hour = 0, int minute = 0, int second = 0)
{
return new DateTime(year, 12, day, hour, minute, second);
}
#endregion
@ -151,41 +175,65 @@
// TODO change
public static TimeSpan Days(this uint number) =>
TimeSpan.FromDays(number);
public static TimeSpan Days(this uint number)
{
return TimeSpan.FromDays(number);
}
public static TimeSpan Hours(this uint number) =>
TimeSpan.FromHours(number);
public static TimeSpan Hours(this uint number)
{
return TimeSpan.FromHours(number);
}
public static TimeSpan Milliseconds(this uint number) =>
TimeSpan.FromSeconds(number);
public static TimeSpan Milliseconds(this uint number)
{
return TimeSpan.FromSeconds(number);
}
public static TimeSpan Minutes(this uint number) =>
TimeSpan.FromMinutes(number);
public static TimeSpan Minutes(this uint number)
{
return TimeSpan.FromMinutes(number);
}
public static TimeSpan Seconds(this uint number) =>
TimeSpan.FromSeconds(number);
public static TimeSpan Seconds(this uint number)
{
return TimeSpan.FromSeconds(number);
}
public static TimeSpan Ticks(this uint number) =>
TimeSpan.FromTicks(number);
public static TimeSpan Ticks(this uint number)
{
return TimeSpan.FromTicks(number);
}
public static TimeSpan Days(this int number) =>
TimeSpan.FromDays(number);
public static TimeSpan Days(this int number)
{
return TimeSpan.FromDays(number);
}
public static TimeSpan Hours(this int number) =>
TimeSpan.FromHours(number);
public static TimeSpan Hours(this int number)
{
return TimeSpan.FromHours(number);
}
public static TimeSpan Milliseconds(this int number) =>
TimeSpan.FromSeconds(number);
public static TimeSpan Milliseconds(this int number)
{
return TimeSpan.FromSeconds(number);
}
public static TimeSpan Minutes(this int number) =>
TimeSpan.FromMinutes(number);
public static TimeSpan Minutes(this int number)
{
return TimeSpan.FromMinutes(number);
}
public static TimeSpan Seconds(this int number) =>
TimeSpan.FromSeconds(number);
public static TimeSpan Seconds(this int number)
{
return TimeSpan.FromSeconds(number);
}
public static TimeSpan Ticks(this int number) =>
TimeSpan.FromTicks(number);
public static TimeSpan Ticks(this int number)
{
return TimeSpan.FromTicks(number);
}
#endregion
@ -198,8 +246,10 @@
/// <returns>Returns <paramref name="max"/> if <paramref name="value"/> is greater than it,
/// <paramref name="min"/> if <paramref name="value"/> is less than it,
/// or <paramref name="value"/> itself otherwise.</returns>
public static int Clamp(this int value, int min, int max) =>
Math.Min(Math.Max(value, min), max);
public static int Clamp(this int value, int min, int max)
{
return Math.Min(Math.Max(value, min), max);
}
/// <summary>
/// Clamps a value between a minimum and a maximum value.
@ -210,8 +260,10 @@
/// <returns>Returns <paramref name="max"/> if <paramref name="value"/> is greater than it,
/// <paramref name="min"/> if <paramref name="value"/> is less than it,
/// or <paramref name="value"/> itself otherwise.</returns>
public static uint Clamp(this uint value, uint min, uint max) =>
Math.Min(Math.Max(value, min), max);
public static uint Clamp(this uint value, uint min, uint max)
{
return Math.Min(Math.Max(value, min), max);
}
/// <summary>
/// Converts the <see cref="Int32"/> to a <see cref="DateTime"/> treating it as a Unix timestamp.
@ -221,24 +273,30 @@
/// to <see langword="false"/>..</param>
/// <returns>Returns a <see cref="DateTime"/> representing <paramref name="timestamp"/> seconds since the Unix
/// epoch.</returns>
public static DateTime FromUnixTimestamp(this int timestamp, bool isMillis = false) =>
((long)timestamp).FromUnixTimestamp(isMillis);
public static DateTime FromUnixTimestamp(this int timestamp, bool isMillis = false)
{
return ((long) timestamp).FromUnixTimestamp(isMillis);
}
/// <summary>
/// Converts the <see cref="UInt32"/> to a <see cref="Byte"/>[].
/// </summary>
/// <param name="number">The number to convert.</param>
/// <returns>Returns a <see cref="Byte"/>[].</returns>
public static byte[] GetBytes(this uint number) =>
BitConverter.GetBytes(number);
public static byte[] GetBytes(this uint number)
{
return BitConverter.GetBytes(number);
}
/// <summary>
/// Converts the <see cref="Int32"/> to a <see cref="Byte"/>[].
/// </summary>
/// <param name="number">The number to convert.</param>
/// <returns>Returns a <see cref="Byte"/>[].</returns>
public static byte[] GetBytes(this int number) =>
BitConverter.GetBytes(number);
public static byte[] GetBytes(this int number)
{
return BitConverter.GetBytes(number);
}
/// <summary>
/// Determines if the <see cref="Int32"/> is a prime number.
@ -246,8 +304,10 @@
/// <param name="number">The number.</param>
/// <returns>Returns <see langword="true"/> if <paramref name="number"/> is prime, <see langword="false"/>
/// otherwise.</returns>
public static bool IsPrime(this int number) =>
((long)number).IsPrime();
public static bool IsPrime(this int number)
{
return ((long) number).IsPrime();
}
/// <summary>
/// Gets an boolean value that represents this integer.
@ -255,8 +315,10 @@
/// <param name="value">The integer.</param>
/// <returns>Returns <see langword="false"/> if <paramref name="value"/> is 0,
/// <see langword="true"/> otherwise.</returns>
public static bool ToBoolean(this int value) =>
((long)value).ToBoolean();
public static bool ToBoolean(this int value)
{
return ((long) value).ToBoolean();
}
/// <summary>
/// Gets an boolean value that represents this integer.
@ -264,7 +326,9 @@
/// <param name="value">The integer.</param>
/// <returns>Returns <see langword="false"/> if <paramref name="value"/> is 0,
/// <see langword="true"/> otherwise.</returns>
public static bool ToBoolean(this uint value) =>
((ulong)value).ToBoolean();
public static bool ToBoolean(this uint value)
{
return ((ulong) value).ToBoolean();
}
}
}

View File

@ -15,38 +15,60 @@
// TODO change
public static TimeSpan Days(this ulong number) =>
TimeSpan.FromDays(number);
public static TimeSpan Days(this ulong number)
{
return TimeSpan.FromDays(number);
}
public static TimeSpan Hours(this ulong number) =>
TimeSpan.FromHours(number);
public static TimeSpan Hours(this ulong number)
{
return TimeSpan.FromHours(number);
}
public static TimeSpan Milliseconds(this ulong number) =>
TimeSpan.FromSeconds(number);
public static TimeSpan Milliseconds(this ulong number)
{
return TimeSpan.FromSeconds(number);
}
public static TimeSpan Minutes(this ulong number) =>
TimeSpan.FromMinutes(number);
public static TimeSpan Minutes(this ulong number)
{
return TimeSpan.FromMinutes(number);
}
public static TimeSpan Seconds(this ulong number) =>
TimeSpan.FromSeconds(number);
public static TimeSpan Seconds(this ulong number)
{
return TimeSpan.FromSeconds(number);
}
public static TimeSpan Days(this long number) =>
TimeSpan.FromDays(number);
public static TimeSpan Days(this long number)
{
return TimeSpan.FromDays(number);
}
public static TimeSpan Hours(this long number) =>
TimeSpan.FromHours(number);
public static TimeSpan Hours(this long number)
{
return TimeSpan.FromHours(number);
}
public static TimeSpan Milliseconds(this long number) =>
TimeSpan.FromSeconds(number);
public static TimeSpan Milliseconds(this long number)
{
return TimeSpan.FromSeconds(number);
}
public static TimeSpan Minutes(this long number) =>
TimeSpan.FromMinutes(number);
public static TimeSpan Minutes(this long number)
{
return TimeSpan.FromMinutes(number);
}
public static TimeSpan Seconds(this long number) =>
TimeSpan.FromSeconds(number);
public static TimeSpan Seconds(this long number)
{
return TimeSpan.FromSeconds(number);
}
public static TimeSpan Ticks(this long number) =>
TimeSpan.FromTicks(number);
public static TimeSpan Ticks(this long number)
{
return TimeSpan.FromTicks(number);
}
#endregion
@ -59,8 +81,10 @@
/// <returns>Returns <paramref name="max"/> if <paramref name="value"/> is greater than it,
/// <paramref name="min"/> if <paramref name="value"/> is less than it,
/// or <paramref name="value"/> itself otherwise.</returns>
public static long Clamp(this long value, long min, long max) =>
Math.Min(Math.Max(value, min), max);
public static long Clamp(this long value, long min, long max)
{
return Math.Min(Math.Max(value, min), max);
}
/// <summary>
/// Clamps a value between a minimum and a maximum value.
@ -71,8 +95,10 @@
/// <returns>Returns <paramref name="max"/> if <paramref name="value"/> is greater than it,
/// <paramref name="min"/> if <paramref name="value"/> is less than it,
/// or <paramref name="value"/> itself otherwise.</returns>
public static ulong Clamp(this ulong value, ulong min, ulong max) =>
Math.Min(Math.Max(value, min), max);
public static ulong Clamp(this ulong value, ulong min, ulong max)
{
return Math.Min(Math.Max(value, min), max);
}
/// <summary>
/// Converts the <see cref="Int64"/> to a <see cref="DateTime"/> treating it as a Unix timestamp.
@ -96,16 +122,20 @@
/// </summary>
/// <param name="number">The number to convert.</param>
/// <returns>Returns a <see cref="Byte"/>[].</returns>
public static byte[] GetBytes(this ulong number) =>
BitConverter.GetBytes(number);
public static byte[] GetBytes(this ulong number)
{
return BitConverter.GetBytes(number);
}
/// <summary>
/// Converts the <see cref="Int64"/> to a <see cref="Byte"/>[].
/// </summary>
/// <param name="number">The number to convert.</param>
/// <returns>Returns a <see cref="Byte"/>[].</returns>
public static byte[] GetBytes(this long number) =>
BitConverter.GetBytes(number);
public static byte[] GetBytes(this long number)
{
return BitConverter.GetBytes(number);
}
/// <summary>
/// Determines if the <see cref="Int64"/> is a prime number.
@ -148,8 +178,10 @@
/// <param name="value">The integer.</param>
/// <returns>Returns <see langword="false"/> if <paramref name="value"/> is 0,
/// <see langword="true"/> otherwise.</returns>
public static bool ToBoolean(this long value) =>
value != 0;
public static bool ToBoolean(this long value)
{
return value != 0;
}
/// <summary>
/// Gets an boolean value that represents this integer.
@ -157,7 +189,9 @@
/// <param name="value">The integer.</param>
/// <returns>Returns <see langword="false"/> if <paramref name="value"/> is 0,
/// <see langword="true"/> otherwise.</returns>
public static bool ToBoolean(this ulong value) =>
value != 0;
public static bool ToBoolean(this ulong value)
{
return value != 0;
}
}
}

View File

@ -19,8 +19,10 @@
/// <typeparam name="T">The collection type.</typeparam>
/// <param name="source">The collection to draw from.</param>
/// <returns>Returns a random element of type <see cref="T"/> from <paramref name="source"/>.</returns>
public static T OneOf<T>(this IEnumerable<T> source) =>
source.OneOf(new Random());
public static T OneOf<T>(this IEnumerable<T> source)
{
return source.OneOf(new Random());
}
/// <summary>
/// Returns a random element from <paramref name="source"/> using the <see cref="Random"/> instance.
@ -29,8 +31,10 @@
/// <param name="source">The collection to draw from.</param>
/// <param name="random">The <see cref="Random"/> instance.</param>
/// <returns>Returns a random element of type <see cref="T"/> from <paramref name="source"/>.</returns>
public static T OneOf<T>(this IEnumerable<T> source, Random random) =>
source.ToList().OneOf(random);
public static T OneOf<T>(this IEnumerable<T> source, Random random)
{
return source.ToList().OneOf(random);
}
/// <summary>
/// Returns a random element from <paramref name="source"/> using a new <see cref="Random"/> instance.
@ -38,8 +42,10 @@
/// <typeparam name="T">The collection type.</typeparam>
/// <param name="source">The collection to draw from.</param>
/// <returns>Returns a random element of type <see cref="T"/> from <paramref name="source"/>.</returns>
public static T OneOf<T>(this IList<T> source) =>
source.OneOf(new Random());
public static T OneOf<T>(this IList<T> source)
{
return source.OneOf(new Random());
}
/// <summary>
/// Returns a random element from <paramref name="source"/> using the <see cref="Random"/> instance.
@ -48,8 +54,10 @@
/// <param name="source">The collection to draw from.</param>
/// <param name="random">The <see cref="Random"/> instance.</param>
/// <returns>Returns a random element of type <see cref="T"/> from <paramref name="source"/>.</returns>
public static T OneOf<T>(this IList<T> source, Random random) =>
random.OneOf(source);
public static T OneOf<T>(this IList<T> source, Random random)
{
return random.OneOf(source);
}
/// <summary>
/// Shuffles an enumerable.
@ -57,8 +65,10 @@
/// <typeparam name="T">The collection type.</typeparam>
/// <param name="source">The collection to shuffle.</param>
/// <returns>Returns <paramref name="source"/> shuffled.</returns>
public static IEnumerable<T> Shuffle<T>(this IEnumerable<T> source) =>
source.Shuffle(new Random());
public static IEnumerable<T> Shuffle<T>(this IEnumerable<T> source)
{
return source.Shuffle(new Random());
}
/// <summary>
/// Shuffles an enumerable.
@ -67,8 +77,10 @@
/// <param name="source">The collection to shuffle.</param>
/// <param name="random">The <see cref="Random"/> instance.</param>
/// <returns>Returns <paramref name="source"/> shuffled.</returns>
public static IEnumerable<T> Shuffle<T>(this IEnumerable<T> source, Random random) =>
source.OrderBy(_ => random.Next());
public static IEnumerable<T> Shuffle<T>(this IEnumerable<T> source, Random random)
{
return source.OrderBy(_ => random.Next());
}
/// <summary>
/// Shuffles a list.
@ -76,8 +88,10 @@
/// <typeparam name="T">The collection type.</typeparam>
/// <param name="source">The collection to shuffle.</param>
/// <returns>Returns <paramref name="source"/> shuffled.</returns>
public static IEnumerable<T> Shuffle<T>(this IList<T> source) =>
source.Shuffle(new Random());
public static IEnumerable<T> Shuffle<T>(this IList<T> source)
{
return source.Shuffle(new Random());
}
/// <summary>
/// Shuffles a list.
@ -86,7 +100,9 @@
/// <param name="source">The collection to shuffle.</param>
/// <param name="random">The <see cref="Random"/> instance.</param>
/// <returns>Returns <paramref name="source"/> shuffled.</returns>
public static IEnumerable<T> Shuffle<T>(this IList<T> source, Random random) =>
source.OrderBy(_ => random.Next());
public static IEnumerable<T> Shuffle<T>(this IList<T> source, Random random)
{
return source.OrderBy(_ => random.Next());
}
}
}

View File

@ -18,8 +18,10 @@
/// generation.
/// </summary>
/// <param name="random">The <see cref="Random"/> instance.</param>
public static bool CoinToss(this Random random) =>
random.Next(2) == 0;
public static bool CoinToss(this Random random)
{
return random.Next(2) == 0;
}
/// <summary>
/// Returns a random element from <paramref name="source"/> using the <see cref="Random"/> instance.
@ -28,8 +30,10 @@
/// <param name="random">The <see cref="Random"/> instance.</param>
/// <param name="source">The collection to draw from.</param>
/// <returns>Returns a random element of type <see cref="T"/> from <paramref name="source"/>.</returns>
public static T OneOf<T>(this Random random, params T[] source) =>
source.ToList().OneOf(random);
public static T OneOf<T>(this Random random, params T[] source)
{
return source.ToList().OneOf(random);
}
/// <summary>
/// Returns a random element from <paramref name="source"/> using the <see cref="Random"/> instance.
@ -38,7 +42,9 @@
/// <param name="random">The <see cref="Random"/> instance.</param>
/// <param name="source">The collection to draw from.</param>
/// <returns>Returns a random element of type <see cref="T"/> from <paramref name="source"/>.</returns>
public static T OneOf<T>(this Random random, IList<T> source) =>
source[random.Next(source.Count)];
public static T OneOf<T>(this Random random, IList<T> source)
{
return source[random.Next(source.Count)];
}
}
}

View File

@ -20,32 +20,40 @@
/// <returns>Returns <paramref name="max"/> if <paramref name="value"/> is greater than it,
/// <paramref name="min"/> if <paramref name="value"/> is less than it,
/// or <paramref name="value"/> itself otherwise.</returns>
public static float Clamp(this float value, float min, float max) =>
Math.Min(Math.Max(value, min), max);
public static float Clamp(this float value, float min, float max)
{
return Math.Min(Math.Max(value, min), max);
}
/// <summary>
/// Converts an angle from degrees to radians.
/// </summary>
/// <param name="angle">The angle in degrees.</param>
/// <returns>Returns <paramref name="angle"/> in radians.</returns>
public static float DegreesToRadians(this float angle) =>
(float)((double)angle).DegreesToRadians();
public static float DegreesToRadians(this float angle)
{
return (float) ((double) angle).DegreesToRadians();
}
/// <summary>
/// Converts the <see cref="Single"/> to a <see cref="Byte"/>[].
/// </summary>
/// <param name="number">The number to convert.</param>
/// <returns>Returns a <see cref="Byte"/>[].</returns>
public static byte[] GetBytes(this float number) =>
BitConverter.GetBytes(number);
public static byte[] GetBytes(this float number)
{
return BitConverter.GetBytes(number);
}
/// <summary>
/// Converts an angle from radians to degrees.
/// </summary>
/// <param name="angle">The angle in radians.</param>
/// <returns>Returns <paramref name="angle"/> in degrees.</returns>
public static float RadiansToDegrees(this float angle) =>
(float)((double)angle).RadiansToDegrees();
public static float RadiansToDegrees(this float angle)
{
return (float) ((double) angle).RadiansToDegrees();
}
/// <summary>
/// Rounds to the nearest value.
@ -53,7 +61,9 @@
/// <param name="v">The value to round.</param>
/// <param name="nearest">The nearest value.</param>
/// <returns>Returns the rounded value.</returns>
public static float Round(this float v, int nearest = 1) =>
(float)((double)v).Round(nearest);
public static float Round(this float v, int nearest = 1)
{
return (float) ((double) v).Round(nearest);
}
}
}

View File

@ -19,16 +19,20 @@
/// </summary>
/// <param name="data">The base-64 string to decode.</param>
/// <returns>Returns the string in plain text.</returns>
public static string Base64Decode(this string data) =>
Convert.FromBase64String(data).GetString();
public static string Base64Decode(this string data)
{
return Convert.FromBase64String(data).GetString();
}
/// <summary>
/// Encodes a base-64 encoded string.
/// </summary>
/// <param name="value">The plain text string to decode.</param>
/// <returns>Returns the string in plain text.</returns>
public static string Base64Encode(this string value) =>
Convert.ToBase64String(value.GetBytes());
public static string Base64Encode(this string value)
{
return Convert.ToBase64String(value.GetBytes());
}
/// <summary>
/// Parses a <see cref="String"/> into an <see cref="Enum"/>.
@ -36,8 +40,10 @@
/// <typeparam name="T">The type of the Enum</typeparam>
/// <param name="value">String value to parse</param>
/// <returns>The Enum corresponding to the stringExtensions</returns>
public static T EnumParse<T>(this string value) =>
value.EnumParse<T>(false);
public static T EnumParse<T>(this string value)
{
return value.EnumParse<T>(false);
}
/// <summary>
/// Parses a <see cref="String"/> into an <see cref="Enum"/>.
@ -77,8 +83,10 @@
/// </summary>
/// <param name="str">The string to convert.</param>
/// <returns>Returns a <see cref="Byte"/>[].</returns>
public static byte[] GetBytes(this string str) =>
str.GetBytes(Encoding.UTF8);
public static byte[] GetBytes(this string str)
{
return str.GetBytes(Encoding.UTF8);
}
/// <summary>
/// Gets a <see cref="Byte"/>[] representing the value the <see cref="String"/> with the provided encoding.
@ -86,8 +94,10 @@
/// <param name="str">The string to convert.</param>
/// <param name="encoding">The encoding to use.</param>
/// <returns>Returns a <see cref="Byte"/>[].</returns>
public static byte[] GetBytes(this string str, Encoding encoding) =>
encoding.GetBytes(str);
public static byte[] GetBytes(this string str, Encoding encoding)
{
return encoding.GetBytes(str);
}
/// <summary>
/// Repeats a string a specified number of times.
@ -135,7 +145,9 @@
/// <param name="str">The <see cref="SecureString"/> to convert.</param>
/// <param name="extension">Whether or not to use this extension method.</param>
/// <returns>Returns a <see cref="String"/>.</returns>
public static string ToString(this SecureString str, bool extension) =>
extension ? (new NetworkCredential(String.Empty, str).Password) : str.ToString();
public static string ToString(this SecureString str, bool extension)
{
return extension ? (new NetworkCredential(String.Empty, str).Password) : str.ToString();
}
}
}