From 90f0e7efd4d0853896d0d845675e624f50e0f9d6 Mon Sep 17 00:00:00 2001 From: Oliver Booth Date: Sat, 18 Apr 2020 14:38:27 +0100 Subject: [PATCH] =?UTF-8?q?=F0=9F=8E=A8=20Ensure=20codebase=20is=20StyleCo?= =?UTF-8?q?p=20&=20FxCop=20compliant?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- X10D/src/BooleanExtensions.cs | 2 -- X10D/src/ComparableExtensions.cs | 3 ++- X10D/src/DictionaryExtensions.cs | 25 +++++++++++-------------- X10D/src/EndPointExtensions.cs | 5 ++--- X10D/src/Int16Extensions.cs | 14 +++++++------- X10D/src/Int32Extensions.cs | 8 ++++---- X10D/src/Int64Extensions.cs | 6 +++--- X10D/src/SingleExtensions.cs | 8 ++++---- X10D/src/StringExtensions.cs | 10 +++++----- X10D/src/StructExtensions.cs | 18 ++++++++++-------- X10D/src/TimeSpanParser.cs | 15 +++++++++------ 11 files changed, 57 insertions(+), 57 deletions(-) diff --git a/X10D/src/BooleanExtensions.cs b/X10D/src/BooleanExtensions.cs index b6ca033..256806f 100644 --- a/X10D/src/BooleanExtensions.cs +++ b/X10D/src/BooleanExtensions.cs @@ -1,7 +1,5 @@ namespace X10D { - using System; - /// /// Extension methods for . /// diff --git a/X10D/src/ComparableExtensions.cs b/X10D/src/ComparableExtensions.cs index d0991ca..bce366d 100644 --- a/X10D/src/ComparableExtensions.cs +++ b/X10D/src/ComparableExtensions.cs @@ -16,7 +16,8 @@ /// 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 + 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/src/DictionaryExtensions.cs b/X10D/src/DictionaryExtensions.cs index ae915bd..22e335c 100644 --- a/X10D/src/DictionaryExtensions.cs +++ b/X10D/src/DictionaryExtensions.cs @@ -1,6 +1,5 @@ namespace X10D { - using System; using System.Collections.Generic; using System.Linq; using System.Text.RegularExpressions; @@ -22,15 +21,13 @@ { static string SanitizeValue(T value) { - return - value is string str && - Regex.IsMatch(str, "\\s") - ? $"\"{str}\"" - : value.ToString(); + return value is string str && + Regex.IsMatch(str, "\\s") + ? $"\"{str}\"" + : value.ToString(); } - IEnumerable strings = - dictionary.Select(o => $"{o.Key}={SanitizeValue(o.Value)}"); + IEnumerable strings = dictionary.Select(o => $"{o.Key}={SanitizeValue(o.Value)}"); return string.Join(";", strings); } @@ -43,7 +40,7 @@ /// Returns a representing the dictionary as a key=value; set. public static string ToConnectionString(this IDictionary dictionary) { - return ((IReadOnlyDictionary) dictionary).ToConnectionString(); + return ((IReadOnlyDictionary)dictionary).ToConnectionString(); } /// @@ -55,7 +52,7 @@ /// Returns a representing the dictionary as a key=value; set. public static string ToConnectionString(this Dictionary dictionary) { - return ((IReadOnlyDictionary) dictionary).ToConnectionString(); + return ((IReadOnlyDictionary)dictionary).ToConnectionString(); } /// @@ -69,8 +66,8 @@ { static string Sanitize(KeyValuePair kvp) { - string key = HttpUtility.UrlEncode(kvp.Key.ToString()); - string value = HttpUtility.UrlEncode(kvp.Value.ToString()); + var key = HttpUtility.UrlEncode(kvp.Key.ToString()); + var value = HttpUtility.UrlEncode(kvp.Value.ToString()); return $"{key}={value}"; } @@ -86,7 +83,7 @@ /// Returns a representing the dictionary as a key=value& set. public static string ToGetParameters(this IDictionary dictionary) { - return ((IReadOnlyDictionary) dictionary).ToGetParameters(); + return ((IReadOnlyDictionary)dictionary).ToGetParameters(); } /// @@ -98,7 +95,7 @@ /// Returns a representing the dictionary as a key=value& set. public static string ToGetParameters(this Dictionary dictionary) { - return ((IReadOnlyDictionary) dictionary).ToGetParameters(); + return ((IReadOnlyDictionary)dictionary).ToGetParameters(); } } } diff --git a/X10D/src/EndPointExtensions.cs b/X10D/src/EndPointExtensions.cs index 42ef242..885cd80 100644 --- a/X10D/src/EndPointExtensions.cs +++ b/X10D/src/EndPointExtensions.cs @@ -1,6 +1,5 @@ namespace X10D { - using System; using System.Net; /// @@ -20,7 +19,7 @@ { IPEndPoint ip => ip.Address.ToString(), DnsEndPoint dns => dns.Host, - _ => string.Empty + _ => string.Empty, }; } @@ -35,7 +34,7 @@ { IPEndPoint ip => ip.Port, DnsEndPoint dns => dns.Port, - _ => 0 + _ => 0, }; } } diff --git a/X10D/src/Int16Extensions.cs b/X10D/src/Int16Extensions.cs index f4f51a2..86d52f7 100644 --- a/X10D/src/Int16Extensions.cs +++ b/X10D/src/Int16Extensions.cs @@ -45,7 +45,7 @@ /// epoch. public static DateTime FromUnixTimestamp(this short timestamp, bool isMillis = false) { - return ((long) timestamp).FromUnixTimestamp(isMillis); + return ((long)timestamp).FromUnixTimestamp(isMillis); } /// @@ -76,7 +76,7 @@ /// otherwise. public static bool IsEven(this short number) { - return ((long) number).IsEven(); + return ((long)number).IsEven(); } /// @@ -87,7 +87,7 @@ /// otherwise. public static bool IsEven(this ushort number) { - return ((ulong) number).IsEven(); + return ((ulong)number).IsEven(); } /// @@ -120,7 +120,7 @@ /// otherwise. public static bool IsPrime(this short number) { - return ((long) number).IsPrime(); + return ((long)number).IsPrime(); } /// @@ -131,7 +131,7 @@ /// otherwise. public static bool IsPrime(this ushort number) { - return ((ulong) number).IsPrime(); + return ((ulong)number).IsPrime(); } /// @@ -142,7 +142,7 @@ /// otherwise. public static bool ToBoolean(this short value) { - return ((long) value).ToBoolean(); + return ((long)value).ToBoolean(); } /// @@ -153,7 +153,7 @@ /// otherwise. public static bool ToBoolean(this ushort value) { - return ((ulong) value).ToBoolean(); + return ((ulong)value).ToBoolean(); } } } diff --git a/X10D/src/Int32Extensions.cs b/X10D/src/Int32Extensions.cs index a46f86c..9d6554b 100644 --- a/X10D/src/Int32Extensions.cs +++ b/X10D/src/Int32Extensions.cs @@ -45,7 +45,7 @@ /// epoch. public static DateTime FromUnixTimestamp(this int timestamp, bool isMillis = false) { - return ((long) timestamp).FromUnixTimestamp(isMillis); + return ((long)timestamp).FromUnixTimestamp(isMillis); } /// @@ -120,7 +120,7 @@ /// otherwise. public static bool IsPrime(this int number) { - return ((long) number).IsPrime(); + return ((long)number).IsPrime(); } /// @@ -131,7 +131,7 @@ /// otherwise. public static bool ToBoolean(this int value) { - return ((long) value).ToBoolean(); + return ((long)value).ToBoolean(); } /// @@ -142,7 +142,7 @@ /// otherwise. public static bool ToBoolean(this uint value) { - return ((ulong) value).ToBoolean(); + return ((ulong)value).ToBoolean(); } } } diff --git a/X10D/src/Int64Extensions.cs b/X10D/src/Int64Extensions.cs index 3983645..e2b7d93 100644 --- a/X10D/src/Int64Extensions.cs +++ b/X10D/src/Int64Extensions.cs @@ -139,8 +139,8 @@ return false; } - long boundary = (long) Math.Floor(Math.Sqrt(number)); - for (int i = 3; i <= boundary; i += 2) + var boundary = (long)Math.Floor(Math.Sqrt(number)); + for (var i = 3; i <= boundary; i += 2) { if (number % i == 0) { @@ -174,7 +174,7 @@ return false; } - ulong boundary = (ulong) Math.Floor(Math.Sqrt(number)); + var boundary = (ulong)Math.Floor(Math.Sqrt(number)); for (uint i = 3; i <= boundary; i += 2) { if (number % i == 0) diff --git a/X10D/src/SingleExtensions.cs b/X10D/src/SingleExtensions.cs index e506663..b62c6a6 100644 --- a/X10D/src/SingleExtensions.cs +++ b/X10D/src/SingleExtensions.cs @@ -28,7 +28,7 @@ /// Returns in radians. public static float DegreesToRadians(this float angle) { - return (float) ((double) angle).DegreesToRadians(); + return (float)((double)angle).DegreesToRadians(); } /// @@ -49,7 +49,7 @@ /// otherwise. public static bool IsEven(this float number) { - return ((double) number).IsEven(); + return ((double)number).IsEven(); } /// @@ -70,7 +70,7 @@ /// Returns in degrees. public static float RadiansToDegrees(this float angle) { - return (float) ((double) angle).RadiansToDegrees(); + return (float)((double)angle).RadiansToDegrees(); } /// @@ -81,7 +81,7 @@ /// Returns the rounded value. public static float Round(this float v, int nearest = 1) { - return (float) ((double) v).Round(nearest); + return (float)((double)v).Round(nearest); } } } diff --git a/X10D/src/StringExtensions.cs b/X10D/src/StringExtensions.cs index 0b5b0b1..a81b880 100644 --- a/X10D/src/StringExtensions.cs +++ b/X10D/src/StringExtensions.cs @@ -36,7 +36,7 @@ /// Parses a into an . /// /// The type of the . - /// The value to parse + /// The value to parse. /// The value corresponding to the . public static T EnumParse(this string value) { @@ -47,9 +47,9 @@ /// Parses a into an . /// /// The type of the . - /// The value to parse + /// The value to parse. /// Whether or not to ignore casing. - /// The value corresponding to the + /// The value corresponding to the . public static T EnumParse(this string value, bool ignoreCase) { if (value is null) @@ -228,8 +228,8 @@ return null; } - SecureString result = new SecureString(); - foreach (char c in str) + var result = new SecureString(); + foreach (var c in str) { result.AppendChar(c); } diff --git a/X10D/src/StructExtensions.cs b/X10D/src/StructExtensions.cs index 6298fcd..563373a 100644 --- a/X10D/src/StructExtensions.cs +++ b/X10D/src/StructExtensions.cs @@ -11,19 +11,20 @@ /// Returns the next value in an using the specified value as a starting point. /// /// An . - /// An value + /// An value. /// Optional. Whether or not to wrap to the to the start of the enum. Defaults to /// true. /// Returns a value. - public static T Next(this T src, bool wrap = true) where T : struct + public static T Next(this T src, bool wrap = true) + where T : struct { if (!typeof(T).IsEnum) { throw new ArgumentException($"Argument {typeof(T).FullName} is not an Enum"); } - T[] arr = (T[])Enum.GetValues(src.GetType()); - int j = Array.IndexOf(arr, src) + 1; + var arr = (T[])Enum.GetValues(src.GetType()); + var j = Array.IndexOf(arr, src) + 1; return arr.Length == j ? arr[wrap ? 0 : j - 1] : arr[j]; } @@ -31,19 +32,20 @@ /// Returns the previous value in an using the specified value as a starting point. /// /// An . - /// An value + /// An value. /// Optional. Whether or not to wrap to the to the end of the enum. Defaults to /// true. /// Returns a value. - public static T Previous(this T src, bool wrap = true) where T : struct + public static T Previous(this T src, bool wrap = true) + where T : struct { if (!typeof(T).IsEnum) { throw new ArgumentException($"Argument {typeof(T).FullName} is not an Enum"); } - T[] arr = (T[])Enum.GetValues(src.GetType()); - int j = Array.IndexOf(arr, src) - 1; + var arr = (T[])Enum.GetValues(src.GetType()); + var j = Array.IndexOf(arr, src) - 1; return j < 0 ? arr[wrap ? arr.Length - 1 : 0] : arr[j]; } } diff --git a/X10D/src/TimeSpanParser.cs b/X10D/src/TimeSpanParser.cs index 54ac8f8..39e6176 100644 --- a/X10D/src/TimeSpanParser.cs +++ b/X10D/src/TimeSpanParser.cs @@ -4,6 +4,9 @@ using System.Diagnostics; using System.Text.RegularExpressions; + /// + /// Represents a class which contains a parser which converts into . + /// public static class TimeSpanParser { /// @@ -16,12 +19,12 @@ public static TimeSpan Parse(string input, IFormatProvider provider = null) { const string realNumberPattern = @"([0-9]*\.[0-9]+|[0-9]+)"; - string pattern = $@"^(?:{realNumberPattern} *w)? *" + - $@"(?:{realNumberPattern} *d)? *" + - $@"(?:{realNumberPattern} *h)? *" + - $@"(?:{realNumberPattern} *m)? *" + - $@"(?:{realNumberPattern} *s)? *" + - $@"(?:{realNumberPattern} *ms)?$"; + var pattern = $"^(?:{realNumberPattern} *w)? *" + + $"(?:{realNumberPattern} *d)? *" + + $"(?:{realNumberPattern} *h)? *" + + $"(?:{realNumberPattern} *m)? *" + + $"(?:{realNumberPattern} *s)? *" + + $"(?:{realNumberPattern} *ms)?$"; Match match = Regex.Match(input, pattern); double weeks = 0, days = 0, hours = 0, minutes = 0, seconds = 0, milliseconds = 0;