From 75a37d44d464f4a788f6c4aa58b990a681ceabc4 Mon Sep 17 00:00:00 2001 From: Oliver Booth Date: Tue, 19 Nov 2019 15:15:32 +0000 Subject: [PATCH] =?UTF-8?q?=F0=9F=94=A8=20Use=20block=20bodies=20instead?= =?UTF-8?q?=20of=20expression=20bodies?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- X10D.Drawing/ImageExtensions.cs | 54 ++++++--- X10D.Unity/Vector3Extensions.cs | 24 ++-- X10D/BooleanExtensions.cs | 6 +- X10D/ByteExtensions.cs | 48 +++++--- X10D/CharExtensions.cs | 6 +- X10D/ComparableExtensions.cs | 6 +- X10D/ConvertibleExtensions.cs | 6 +- X10D/DateTimeExtensions.cs | 48 +++++--- X10D/DoubleExtensions.cs | 30 +++-- X10D/EndPointExtensions.cs | 12 +- X10D/Int16Extensions.cs | 120 +++++++++++++------- X10D/Int32Extensions.cs | 192 +++++++++++++++++++++----------- X10D/Int64Extensions.cs | 102 +++++++++++------ X10D/ListExtensions.cs | 48 +++++--- X10D/RandomExtensions.cs | 18 ++- X10D/SingleExtensions.cs | 30 +++-- X10D/StringExtensions.cs | 36 ++++-- 17 files changed, 524 insertions(+), 262 deletions(-) diff --git a/X10D.Drawing/ImageExtensions.cs b/X10D.Drawing/ImageExtensions.cs index 6a7fceb..a22786c 100644 --- a/X10D.Drawing/ImageExtensions.cs +++ b/X10D.Drawing/ImageExtensions.cs @@ -21,8 +21,10 @@ /// /// The image to convert. /// Returns an . - public static async Task ToSquareAsync(this Image image) => - await Task.Run(image.ToSquare); + public static async Task ToSquareAsync(this Image image) + { + return await Task.Run(image.ToSquare); + } /// /// Asynchronously converts the image so that its aspect ratio is 1:1, surrounding any new area with @@ -31,8 +33,10 @@ /// The image to convert. /// The new size of the image, i.e. the value of both the width and height. /// Returns an . - public static async Task ToSquareAsync(this Image image, int size) => - await Task.Run(() => image.ToSquare(size)); + public static async Task ToSquareAsync(this Image image, int size) + { + return await Task.Run(() => image.ToSquare(size)); + } /// /// Asynchronously converts the image so that its aspect ratio is 1:1, surrounding any new area with a @@ -42,8 +46,10 @@ /// The new size of the image, i.e. the value of both the width and height. /// The background color to fill. /// Returns an . - public static async Task ToSquareAsync(this Image image, int size, Color background) => - await Task.Run(() => image.ToSquare(size, background)); + public static async Task ToSquareAsync(this Image image, int size, Color background) + { + return await Task.Run(() => image.ToSquare(size, background)); + } /// /// Asynchronously converts the image so that its aspect ratio is 1:1, surrounding any new area with a @@ -52,16 +58,20 @@ /// The image to convert. /// The background color to fill. /// Returns an . - public static async Task ToSquareAsync(this Image image, Color background) => - await Task.Run(() => image.ToSquare(background)); + public static async Task ToSquareAsync(this Image image, Color background) + { + return await Task.Run(() => image.ToSquare(background)); + } /// /// Converts the image so that its aspect ratio is 1:1, surrounding any new area with transparency. /// /// The image to convert. /// Returns an . - public static Image ToSquare(this Image image) => - image.ToSquare(Color.Transparent); + public static Image ToSquare(this Image image) + { + return image.ToSquare(Color.Transparent); + } /// /// Converts the image so that its aspect ratio is 1:1, surrounding any new area with transparency. @@ -69,8 +79,10 @@ /// The image to convert. /// The new size of the image, i.e. the value of both the width and height. /// Returns an . - 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); + } /// /// Converts the image so that its aspect ratio is 1:1, surrounding any new area with a specified background @@ -117,8 +129,10 @@ /// The new width. /// The new height. /// Returns a new . - public static async Task ScaleAsync(this Image image, int width, int height) => - await Task.Run(() => image.Scale(width, height)); + public static async Task ScaleAsync(this Image image, int width, int height) + { + return await Task.Run(() => image.Scale(width, height)); + } /// /// Asynchronously scales the image. @@ -126,8 +140,10 @@ /// The image to scale. /// The scale factor. /// Returns a new . - public static async Task ScaleAsync(this Image image, float factor) => - await Task.Run(() => image.Scale(factor)); + public static async Task ScaleAsync(this Image image, float factor) + { + return await Task.Run(() => image.Scale(factor)); + } /// /// Scales the image. @@ -135,8 +151,10 @@ /// The image to scale. /// The scale factor. /// Returns a new . - 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)); + } /// /// Scales the image. diff --git a/X10D.Unity/Vector3Extensions.cs b/X10D.Unity/Vector3Extensions.cs index 66a4c6a..2c80cac 100644 --- a/X10D.Unity/Vector3Extensions.cs +++ b/X10D.Unity/Vector3Extensions.cs @@ -32,31 +32,39 @@ /// The vector to round. /// The nearest value. /// Returns a containing the rounded values. - 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)); + } /// /// Inverts the X component of a vector. /// /// The vector to evaluate. /// Returns a whose values are (-X, Y, Z). - 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); + } /// /// Inverts the Y component of a vector. /// /// The vector to evaluate. /// Returns a whose values are (X, -Y, Z). - 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); + } /// /// Inverts the Z component of a vector. /// /// The vector to evaluate. /// Returns a whose values are (X, Y, -Z). - 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); + } } } diff --git a/X10D/BooleanExtensions.cs b/X10D/BooleanExtensions.cs index 8c85799..100733a 100644 --- a/X10D/BooleanExtensions.cs +++ b/X10D/BooleanExtensions.cs @@ -16,7 +16,9 @@ /// /// The boolean. /// Returns 1 if is , 0 otherwise. - public static int ToInt32(this bool value) => - value ? 1 : 0; + public static int ToInt32(this bool value) + { + return value ? 1 : 0; + } } } diff --git a/X10D/ByteExtensions.cs b/X10D/ByteExtensions.cs index 46e112d..7f03889 100644 --- a/X10D/ByteExtensions.cs +++ b/X10D/ByteExtensions.cs @@ -19,56 +19,70 @@ /// /// The bytes to get. /// Returns a . - public static string AsString(this IEnumerable bytes) => - BitConverter.ToString(bytes.ToArray()); + public static string AsString(this IEnumerable bytes) + { + return BitConverter.ToString(bytes.ToArray()); + } /// /// Converts the [] to an . /// /// The bytes to convert. /// Returns an . - public static short GetInt16(this IEnumerable bytes) => - BitConverter.ToInt16(bytes.ToArray(), 0); + public static short GetInt16(this IEnumerable bytes) + { + return BitConverter.ToInt16(bytes.ToArray(), 0); + } /// /// Converts the [] to an . /// /// The bytes to convert. /// Returns an . - public static int GetInt32(this IEnumerable bytes) => - BitConverter.ToInt32(bytes.ToArray(), 0); + public static int GetInt32(this IEnumerable bytes) + { + return BitConverter.ToInt32(bytes.ToArray(), 0); + } /// /// Converts the [] to an . /// /// The bytes to convert. /// Returns an . - public static long GetInt64(this IEnumerable bytes) => - BitConverter.ToInt64(bytes.ToArray(), 0); + public static long GetInt64(this IEnumerable bytes) + { + return BitConverter.ToInt64(bytes.ToArray(), 0); + } /// /// Converts the [] to a . /// /// The bytes to convert. /// Returns an . - public static ushort GetUInt16(this IEnumerable bytes) => - BitConverter.ToUInt16(bytes.ToArray(), 0); + public static ushort GetUInt16(this IEnumerable bytes) + { + return BitConverter.ToUInt16(bytes.ToArray(), 0); + } /// /// Converts the [] to an . /// /// The bytes to convert. /// Returns an . - public static uint GetUInt32(this IEnumerable bytes) => - BitConverter.ToUInt32(bytes.ToArray(), 0); + public static uint GetUInt32(this IEnumerable bytes) + { + return BitConverter.ToUInt32(bytes.ToArray(), 0); + } /// /// Converts the [] to an . /// /// The bytes to convert. /// Returns an . - public static ulong GetUInt64(this IEnumerable bytes) => - BitConverter.ToUInt64(bytes.ToArray(), 0); + public static ulong GetUInt64(this IEnumerable bytes) + { + return BitConverter.ToUInt64(bytes.ToArray(), 0); + } /// /// Gets a representing the value the [] with @@ -76,8 +90,10 @@ /// /// The bytes to convert. /// Returns a . - public static string GetString(this IEnumerable bytes) => - bytes.GetString(Encoding.UTF8); + public static string GetString(this IEnumerable bytes) + { + return bytes.GetString(Encoding.UTF8); + } /// /// Gets a representing the value the [] with the provided encoding. diff --git a/X10D/CharExtensions.cs b/X10D/CharExtensions.cs index 249244b..328f53f 100644 --- a/X10D/CharExtensions.cs +++ b/X10D/CharExtensions.cs @@ -18,7 +18,9 @@ /// The repeat count. /// Returns a whose value is repeated /// times. - 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); + } } } diff --git a/X10D/ComparableExtensions.cs b/X10D/ComparableExtensions.cs index 4c32328..f8919d6 100644 --- a/X10D/ComparableExtensions.cs +++ b/X10D/ComparableExtensions.cs @@ -20,7 +20,9 @@ /// The exclusive upper bound. /// Returns if the value is between the bounds, /// otherwise. - public static bool Between(this T actual, T lower, T upper) where T : IComparable => - actual.CompareTo(lower) > 0 && actual.CompareTo(upper) < 0; + public static bool Between(this T actual, T lower, T upper) where T : IComparable + { + return actual.CompareTo(lower) > 0 && actual.CompareTo(upper) < 0; + } } } diff --git a/X10D/ConvertibleExtensions.cs b/X10D/ConvertibleExtensions.cs index 09278db..39fbefc 100644 --- a/X10D/ConvertibleExtensions.cs +++ b/X10D/ConvertibleExtensions.cs @@ -17,8 +17,10 @@ /// The type to convert to. /// The object to convert. /// Returns the value converted to . - public static T To(this IConvertible obj) => - (T)Convert.ChangeType(obj, typeof(T)); + public static T To(this IConvertible obj) + { + return (T) Convert.ChangeType(obj, typeof(T)); + } /// /// Converts the object to another type, returning the default value on failure. diff --git a/X10D/DateTimeExtensions.cs b/X10D/DateTimeExtensions.cs index bcb021f..1bbcbe1 100644 --- a/X10D/DateTimeExtensions.cs +++ b/X10D/DateTimeExtensions.cs @@ -15,8 +15,10 @@ /// Calculates someone's age based on a date of birth. /// /// The date of birth. - 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); + } /// /// Gets a DateTime representing the first specified day in the current month @@ -40,8 +42,10 @@ /// Gets a representing the first day in the current month. /// /// The current date. - 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); + } /// /// Gets a representing the last day in the current month. @@ -72,8 +76,10 @@ /// Gets a representing midnight on the current date. /// /// The current date. - 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); + } /// /// Gets a representing the first date following the current date which falls on the @@ -98,8 +104,10 @@ /// Gets a representing noon on the current date. /// /// The current date. - 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); + } /// /// Sets the time of the current date with minute precision. @@ -107,8 +115,10 @@ /// The current date. /// The hour. /// The minute. - 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); + } /// /// Sets the time of the current date with second precision. @@ -118,8 +128,10 @@ /// The minute. /// The second. /// - 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); + } /// /// Sets the time of the current date with millisecond precision. @@ -129,8 +141,10 @@ /// The minute. /// The second. /// The millisecond. - 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); + } /// /// Converts the to a Unix timestamp. @@ -151,7 +165,9 @@ /// The to copy. /// The year to set. /// Returns a . - 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); + } } } diff --git a/X10D/DoubleExtensions.cs b/X10D/DoubleExtensions.cs index 9974f41..3fa650b 100644 --- a/X10D/DoubleExtensions.cs +++ b/X10D/DoubleExtensions.cs @@ -20,32 +20,40 @@ /// Returns if is greater than it, /// if is less than it, /// or itself otherwise. - 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); + } /// /// Converts an angle from degrees to radians. /// /// The angle in degrees. /// Returns in radians. - 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; + } /// /// Converts the to a []. /// /// The number to convert. /// Returns a []. - public static byte[] GetBytes(this double number) => - BitConverter.GetBytes(number); + public static byte[] GetBytes(this double number) + { + return BitConverter.GetBytes(number); + } /// /// Converts an angle from radians to degrees. /// /// The angle in radians. /// Returns in degrees. - 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); + } /// /// Rounds to the nearest value. @@ -53,7 +61,9 @@ /// The value to round. /// The nearest value. /// Returns the rounded value. - 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; + } } } diff --git a/X10D/EndPointExtensions.cs b/X10D/EndPointExtensions.cs index c263d6c..80325ee 100644 --- a/X10D/EndPointExtensions.cs +++ b/X10D/EndPointExtensions.cs @@ -18,25 +18,29 @@ /// The endpoint whose hostname to get. /// Returns a representing the hostname, which may be an IP or a DNS, or empty /// string on failure. - 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 }; + } /// /// Gets the endpoint port. /// /// The endpoint whose port to get. /// Returns an representing the port, or 0 on failure. - 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 }; + } } } diff --git a/X10D/Int16Extensions.cs b/X10D/Int16Extensions.cs index 43723dc..85914fa 100644 --- a/X10D/Int16Extensions.cs +++ b/X10D/Int16Extensions.cs @@ -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 if is greater than it, /// if is less than it, /// or itself otherwise. - 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); + } /// /// Clamps a value between a minimum and a maximum value. @@ -74,8 +100,10 @@ /// Returns if is greater than it, /// if is less than it, /// or itself otherwise. - 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); + } /// /// Converts the to a treating it as a Unix timestamp. @@ -85,24 +113,30 @@ /// to .. /// Returns a representing seconds since the Unix /// epoch. - 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); + } /// /// Converts the to a []. /// /// The number to convert. /// Returns a []. - public static byte[] GetBytes(this ushort number) => - BitConverter.GetBytes(number); + public static byte[] GetBytes(this ushort number) + { + return BitConverter.GetBytes(number); + } /// /// Converts the to a []. /// /// The number to convert. /// Returns a []. - public static byte[] GetBytes(this short number) => - BitConverter.GetBytes(number); + public static byte[] GetBytes(this short number) + { + return BitConverter.GetBytes(number); + } /// /// Determines if the is a prime number. @@ -110,8 +144,10 @@ /// The number. /// Returns if is prime, /// otherwise. - public static bool IsPrime(this short number) => - ((long)number).IsPrime(); + public static bool IsPrime(this short number) + { + return ((long) number).IsPrime(); + } /// /// Gets an boolean value that represents this integer. @@ -119,8 +155,10 @@ /// The integer. /// Returns if is 0, /// otherwise. - public static bool ToBoolean(this short value) => - ((long)value).ToBoolean(); + public static bool ToBoolean(this short value) + { + return ((long) value).ToBoolean(); + } /// /// Gets an boolean value that represents this integer. @@ -128,7 +166,9 @@ /// The integer. /// Returns if is 0, /// otherwise. - public static bool ToBoolean(this ushort value) => - ((ulong)value).ToBoolean(); + public static bool ToBoolean(this ushort value) + { + return ((ulong) value).ToBoolean(); + } } } diff --git a/X10D/Int32Extensions.cs b/X10D/Int32Extensions.cs index fa98217..42a36b3 100644 --- a/X10D/Int32Extensions.cs +++ b/X10D/Int32Extensions.cs @@ -21,8 +21,10 @@ /// The hour. /// The minute. /// The second. - 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); + } /// /// Returns a where the month is February. @@ -32,8 +34,10 @@ /// The hour. /// The minute. /// The second. - 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); + } /// /// Returns a where the month is March. @@ -43,8 +47,10 @@ /// The hour. /// The minute. /// The second. - 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); + } /// /// Returns a where the month is April. @@ -54,8 +60,10 @@ /// The hour. /// The minute. /// The second. - 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); + } /// /// Returns a where the month is May. @@ -65,8 +73,10 @@ /// The hour. /// The minute. /// The second. - 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); + } /// /// Returns a where the month is June. @@ -76,8 +86,10 @@ /// The hour. /// The minute. /// The second. - 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); + } /// /// Returns a where the month is July. @@ -87,8 +99,10 @@ /// The hour. /// The minute. /// The second. - 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); + } /// /// Returns a where the month is August. @@ -98,8 +112,10 @@ /// The hour. /// The minute. /// The second. - 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); + } /// /// Returns a where the month is September. @@ -109,8 +125,10 @@ /// The hour. /// The minute. /// The second. - 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); + } /// /// Returns a where the month is October. @@ -120,8 +138,10 @@ /// The hour. /// The minute. /// The second. - 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); + } /// /// Returns a where the month is November. @@ -131,8 +151,10 @@ /// The hour. /// The minute. /// The second. - 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); + } /// /// Returns a where the month is December. @@ -142,8 +164,10 @@ /// The hour. /// The minute. /// The second. - 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 if is greater than it, /// if is less than it, /// or itself otherwise. - 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); + } /// /// Clamps a value between a minimum and a maximum value. @@ -210,8 +260,10 @@ /// Returns if is greater than it, /// if is less than it, /// or itself otherwise. - 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); + } /// /// Converts the to a treating it as a Unix timestamp. @@ -221,24 +273,30 @@ /// to .. /// Returns a representing seconds since the Unix /// epoch. - 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); + } /// /// Converts the to a []. /// /// The number to convert. /// Returns a []. - public static byte[] GetBytes(this uint number) => - BitConverter.GetBytes(number); + public static byte[] GetBytes(this uint number) + { + return BitConverter.GetBytes(number); + } /// /// Converts the to a []. /// /// The number to convert. /// Returns a []. - public static byte[] GetBytes(this int number) => - BitConverter.GetBytes(number); + public static byte[] GetBytes(this int number) + { + return BitConverter.GetBytes(number); + } /// /// Determines if the is a prime number. @@ -246,8 +304,10 @@ /// The number. /// Returns if is prime, /// otherwise. - public static bool IsPrime(this int number) => - ((long)number).IsPrime(); + public static bool IsPrime(this int number) + { + return ((long) number).IsPrime(); + } /// /// Gets an boolean value that represents this integer. @@ -255,8 +315,10 @@ /// The integer. /// Returns if is 0, /// otherwise. - public static bool ToBoolean(this int value) => - ((long)value).ToBoolean(); + public static bool ToBoolean(this int value) + { + return ((long) value).ToBoolean(); + } /// /// Gets an boolean value that represents this integer. @@ -264,7 +326,9 @@ /// The integer. /// Returns if is 0, /// otherwise. - public static bool ToBoolean(this uint value) => - ((ulong)value).ToBoolean(); + public static bool ToBoolean(this uint value) + { + return ((ulong) value).ToBoolean(); + } } } diff --git a/X10D/Int64Extensions.cs b/X10D/Int64Extensions.cs index d8c6cb7..fc605f4 100644 --- a/X10D/Int64Extensions.cs +++ b/X10D/Int64Extensions.cs @@ -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 if is greater than it, /// if is less than it, /// or itself otherwise. - 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); + } /// /// Clamps a value between a minimum and a maximum value. @@ -71,8 +95,10 @@ /// Returns if is greater than it, /// if is less than it, /// or itself otherwise. - 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); + } /// /// Converts the to a treating it as a Unix timestamp. @@ -96,16 +122,20 @@ /// /// The number to convert. /// Returns a []. - public static byte[] GetBytes(this ulong number) => - BitConverter.GetBytes(number); + public static byte[] GetBytes(this ulong number) + { + return BitConverter.GetBytes(number); + } /// /// Converts the to a []. /// /// The number to convert. /// Returns a []. - public static byte[] GetBytes(this long number) => - BitConverter.GetBytes(number); + public static byte[] GetBytes(this long number) + { + return BitConverter.GetBytes(number); + } /// /// Determines if the is a prime number. @@ -148,8 +178,10 @@ /// The integer. /// Returns if is 0, /// otherwise. - public static bool ToBoolean(this long value) => - value != 0; + public static bool ToBoolean(this long value) + { + return value != 0; + } /// /// Gets an boolean value that represents this integer. @@ -157,7 +189,9 @@ /// The integer. /// Returns if is 0, /// otherwise. - public static bool ToBoolean(this ulong value) => - value != 0; + public static bool ToBoolean(this ulong value) + { + return value != 0; + } } } diff --git a/X10D/ListExtensions.cs b/X10D/ListExtensions.cs index bcc7886..cc2003e 100644 --- a/X10D/ListExtensions.cs +++ b/X10D/ListExtensions.cs @@ -19,8 +19,10 @@ /// The collection type. /// The collection to draw from. /// Returns a random element of type from . - public static T OneOf(this IEnumerable source) => - source.OneOf(new Random()); + public static T OneOf(this IEnumerable source) + { + return source.OneOf(new Random()); + } /// /// Returns a random element from using the instance. @@ -29,8 +31,10 @@ /// The collection to draw from. /// The instance. /// Returns a random element of type from . - public static T OneOf(this IEnumerable source, Random random) => - source.ToList().OneOf(random); + public static T OneOf(this IEnumerable source, Random random) + { + return source.ToList().OneOf(random); + } /// /// Returns a random element from using a new instance. @@ -38,8 +42,10 @@ /// The collection type. /// The collection to draw from. /// Returns a random element of type from . - public static T OneOf(this IList source) => - source.OneOf(new Random()); + public static T OneOf(this IList source) + { + return source.OneOf(new Random()); + } /// /// Returns a random element from using the instance. @@ -48,8 +54,10 @@ /// The collection to draw from. /// The instance. /// Returns a random element of type from . - public static T OneOf(this IList source, Random random) => - random.OneOf(source); + public static T OneOf(this IList source, Random random) + { + return random.OneOf(source); + } /// /// Shuffles an enumerable. @@ -57,8 +65,10 @@ /// The collection type. /// The collection to shuffle. /// Returns shuffled. - public static IEnumerable Shuffle(this IEnumerable source) => - source.Shuffle(new Random()); + public static IEnumerable Shuffle(this IEnumerable source) + { + return source.Shuffle(new Random()); + } /// /// Shuffles an enumerable. @@ -67,8 +77,10 @@ /// The collection to shuffle. /// The instance. /// Returns shuffled. - public static IEnumerable Shuffle(this IEnumerable source, Random random) => - source.OrderBy(_ => random.Next()); + public static IEnumerable Shuffle(this IEnumerable source, Random random) + { + return source.OrderBy(_ => random.Next()); + } /// /// Shuffles a list. @@ -76,8 +88,10 @@ /// The collection type. /// The collection to shuffle. /// Returns shuffled. - public static IEnumerable Shuffle(this IList source) => - source.Shuffle(new Random()); + public static IEnumerable Shuffle(this IList source) + { + return source.Shuffle(new Random()); + } /// /// Shuffles a list. @@ -86,7 +100,9 @@ /// The collection to shuffle. /// The instance. /// Returns shuffled. - public static IEnumerable Shuffle(this IList source, Random random) => - source.OrderBy(_ => random.Next()); + public static IEnumerable Shuffle(this IList source, Random random) + { + return source.OrderBy(_ => random.Next()); + } } } diff --git a/X10D/RandomExtensions.cs b/X10D/RandomExtensions.cs index 2503418..42af3d4 100644 --- a/X10D/RandomExtensions.cs +++ b/X10D/RandomExtensions.cs @@ -18,8 +18,10 @@ /// generation. /// /// The instance. - public static bool CoinToss(this Random random) => - random.Next(2) == 0; + public static bool CoinToss(this Random random) + { + return random.Next(2) == 0; + } /// /// Returns a random element from using the instance. @@ -28,8 +30,10 @@ /// The instance. /// The collection to draw from. /// Returns a random element of type from . - public static T OneOf(this Random random, params T[] source) => - source.ToList().OneOf(random); + public static T OneOf(this Random random, params T[] source) + { + return source.ToList().OneOf(random); + } /// /// Returns a random element from using the instance. @@ -38,7 +42,9 @@ /// The instance. /// The collection to draw from. /// Returns a random element of type from . - public static T OneOf(this Random random, IList source) => - source[random.Next(source.Count)]; + public static T OneOf(this Random random, IList source) + { + return source[random.Next(source.Count)]; + } } } diff --git a/X10D/SingleExtensions.cs b/X10D/SingleExtensions.cs index ef4357c..f3b65f6 100644 --- a/X10D/SingleExtensions.cs +++ b/X10D/SingleExtensions.cs @@ -20,32 +20,40 @@ /// Returns if is greater than it, /// if is less than it, /// or itself otherwise. - 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); + } /// /// Converts an angle from degrees to radians. /// /// The angle in degrees. /// Returns in radians. - public static float DegreesToRadians(this float angle) => - (float)((double)angle).DegreesToRadians(); + public static float DegreesToRadians(this float angle) + { + return (float) ((double) angle).DegreesToRadians(); + } /// /// Converts the to a []. /// /// The number to convert. /// Returns a []. - public static byte[] GetBytes(this float number) => - BitConverter.GetBytes(number); + public static byte[] GetBytes(this float number) + { + return BitConverter.GetBytes(number); + } /// /// Converts an angle from radians to degrees. /// /// The angle in radians. /// Returns in degrees. - public static float RadiansToDegrees(this float angle) => - (float)((double)angle).RadiansToDegrees(); + public static float RadiansToDegrees(this float angle) + { + return (float) ((double) angle).RadiansToDegrees(); + } /// /// Rounds to the nearest value. @@ -53,7 +61,9 @@ /// The value to round. /// The nearest value. /// Returns the rounded value. - 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); + } } } diff --git a/X10D/StringExtensions.cs b/X10D/StringExtensions.cs index b236cf5..0cd1903 100644 --- a/X10D/StringExtensions.cs +++ b/X10D/StringExtensions.cs @@ -19,16 +19,20 @@ /// /// The base-64 string to decode. /// Returns the string in plain text. - public static string Base64Decode(this string data) => - Convert.FromBase64String(data).GetString(); + public static string Base64Decode(this string data) + { + return Convert.FromBase64String(data).GetString(); + } /// /// Encodes a base-64 encoded string. /// /// The plain text string to decode. /// Returns the string in plain text. - public static string Base64Encode(this string value) => - Convert.ToBase64String(value.GetBytes()); + public static string Base64Encode(this string value) + { + return Convert.ToBase64String(value.GetBytes()); + } /// /// Parses a into an . @@ -36,8 +40,10 @@ /// The type of the Enum /// String value to parse /// The Enum corresponding to the stringExtensions - public static T EnumParse(this string value) => - value.EnumParse(false); + public static T EnumParse(this string value) + { + return value.EnumParse(false); + } /// /// Parses a into an . @@ -77,8 +83,10 @@ /// /// The string to convert. /// Returns a []. - public static byte[] GetBytes(this string str) => - str.GetBytes(Encoding.UTF8); + public static byte[] GetBytes(this string str) + { + return str.GetBytes(Encoding.UTF8); + } /// /// Gets a [] representing the value the with the provided encoding. @@ -86,8 +94,10 @@ /// The string to convert. /// The encoding to use. /// Returns a []. - 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); + } /// /// Repeats a string a specified number of times. @@ -135,7 +145,9 @@ /// The to convert. /// Whether or not to use this extension method. /// Returns a . - 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(); + } } }