1
0
mirror of https://github.com/oliverbooth/X10D synced 2024-11-23 00:18:47 +00:00

🎨 Ensure codebase is StyleCop & FxCop compliant

This commit is contained in:
Oliver Booth 2020-04-18 14:38:27 +01:00
parent a2f113237d
commit 90f0e7efd4
No known key found for this signature in database
GPG Key ID: 0D7F2EF1C8D2B9C0
11 changed files with 57 additions and 57 deletions

View File

@ -1,7 +1,5 @@
namespace X10D
{
using System;
/// <summary>
/// Extension methods for <see cref="bool"/>.
/// </summary>

View File

@ -16,7 +16,8 @@
/// <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>
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

@ -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>(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<string> strings =
dictionary.Select(o => $"{o.Key}={SanitizeValue(o.Value)}");
IEnumerable<string> strings = dictionary.Select(o => $"{o.Key}={SanitizeValue(o.Value)}");
return string.Join(";", strings);
}
@ -43,7 +40,7 @@
/// <returns>Returns a <see cref="string"/> representing the dictionary as a key=value; set.</returns>
public static string ToConnectionString<T1, T2>(this IDictionary<T1, T2> dictionary)
{
return ((IReadOnlyDictionary<T1, T2>) dictionary).ToConnectionString();
return ((IReadOnlyDictionary<T1, T2>)dictionary).ToConnectionString();
}
/// <summary>
@ -55,7 +52,7 @@
/// <returns>Returns a <see cref="string"/> representing the dictionary as a key=value; set.</returns>
public static string ToConnectionString<T1, T2>(this Dictionary<T1, T2> dictionary)
{
return ((IReadOnlyDictionary<T1, T2>) dictionary).ToConnectionString();
return ((IReadOnlyDictionary<T1, T2>)dictionary).ToConnectionString();
}
/// <summary>
@ -69,8 +66,8 @@
{
static string Sanitize(KeyValuePair<T1, T2> 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>Returns a <see cref="string"/> representing the dictionary as a key=value& set.</returns>
public static string ToGetParameters<T1, T2>(this IDictionary<T1, T2> dictionary)
{
return ((IReadOnlyDictionary<T1, T2>) dictionary).ToGetParameters();
return ((IReadOnlyDictionary<T1, T2>)dictionary).ToGetParameters();
}
/// <summary>
@ -98,7 +95,7 @@
/// <returns>Returns a <see cref="string"/> representing the dictionary as a key=value& set.</returns>
public static string ToGetParameters<T1, T2>(this Dictionary<T1, T2> dictionary)
{
return ((IReadOnlyDictionary<T1, T2>) dictionary).ToGetParameters();
return ((IReadOnlyDictionary<T1, T2>)dictionary).ToGetParameters();
}
}
}

View File

@ -1,6 +1,5 @@
namespace X10D
{
using System;
using System.Net;
/// <summary>
@ -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,
};
}
}

View File

@ -45,7 +45,7 @@
/// epoch.</returns>
public static DateTime FromUnixTimestamp(this short timestamp, bool isMillis = false)
{
return ((long) timestamp).FromUnixTimestamp(isMillis);
return ((long)timestamp).FromUnixTimestamp(isMillis);
}
/// <summary>
@ -76,7 +76,7 @@
/// otherwise.</returns>
public static bool IsEven(this short number)
{
return ((long) number).IsEven();
return ((long)number).IsEven();
}
/// <summary>
@ -87,7 +87,7 @@
/// otherwise.</returns>
public static bool IsEven(this ushort number)
{
return ((ulong) number).IsEven();
return ((ulong)number).IsEven();
}
/// <summary>
@ -120,7 +120,7 @@
/// otherwise.</returns>
public static bool IsPrime(this short number)
{
return ((long) number).IsPrime();
return ((long)number).IsPrime();
}
/// <summary>
@ -131,7 +131,7 @@
/// otherwise.</returns>
public static bool IsPrime(this ushort number)
{
return ((ulong) number).IsPrime();
return ((ulong)number).IsPrime();
}
/// <summary>
@ -142,7 +142,7 @@
/// <see langword="true"/> otherwise.</returns>
public static bool ToBoolean(this short value)
{
return ((long) value).ToBoolean();
return ((long)value).ToBoolean();
}
/// <summary>
@ -153,7 +153,7 @@
/// <see langword="true"/> otherwise.</returns>
public static bool ToBoolean(this ushort value)
{
return ((ulong) value).ToBoolean();
return ((ulong)value).ToBoolean();
}
}
}

View File

@ -45,7 +45,7 @@
/// epoch.</returns>
public static DateTime FromUnixTimestamp(this int timestamp, bool isMillis = false)
{
return ((long) timestamp).FromUnixTimestamp(isMillis);
return ((long)timestamp).FromUnixTimestamp(isMillis);
}
/// <summary>
@ -120,7 +120,7 @@
/// otherwise.</returns>
public static bool IsPrime(this int number)
{
return ((long) number).IsPrime();
return ((long)number).IsPrime();
}
/// <summary>
@ -131,7 +131,7 @@
/// <see langword="true"/> otherwise.</returns>
public static bool ToBoolean(this int value)
{
return ((long) value).ToBoolean();
return ((long)value).ToBoolean();
}
/// <summary>
@ -142,7 +142,7 @@
/// <see langword="true"/> otherwise.</returns>
public static bool ToBoolean(this uint value)
{
return ((ulong) value).ToBoolean();
return ((ulong)value).ToBoolean();
}
}
}

View File

@ -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)

View File

@ -28,7 +28,7 @@
/// <returns>Returns <paramref name="angle"/> in radians.</returns>
public static float DegreesToRadians(this float angle)
{
return (float) ((double) angle).DegreesToRadians();
return (float)((double)angle).DegreesToRadians();
}
/// <summary>
@ -49,7 +49,7 @@
/// otherwise.</returns>
public static bool IsEven(this float number)
{
return ((double) number).IsEven();
return ((double)number).IsEven();
}
/// <summary>
@ -70,7 +70,7 @@
/// <returns>Returns <paramref name="angle"/> in degrees.</returns>
public static float RadiansToDegrees(this float angle)
{
return (float) ((double) angle).RadiansToDegrees();
return (float)((double)angle).RadiansToDegrees();
}
/// <summary>
@ -81,7 +81,7 @@
/// <returns>Returns the rounded value.</returns>
public static float Round(this float v, int nearest = 1)
{
return (float) ((double) v).Round(nearest);
return (float)((double)v).Round(nearest);
}
}
}

View File

@ -36,7 +36,7 @@
/// Parses a <see cref="string"/> into an <see cref="Enum"/>.
/// </summary>
/// <typeparam name="T">The type of the <see cref="Enum"/>.</typeparam>
/// <param name="value">The <see cref="string"/> value to parse</param>
/// <param name="value">The <see cref="string"/> value to parse.</param>
/// <returns>The <see cref="Enum"/> value corresponding to the <see cref="string"/>.</returns>
public static T EnumParse<T>(this string value)
{
@ -47,9 +47,9 @@
/// Parses a <see cref="string"/> into an <see cref="Enum"/>.
/// </summary>
/// <typeparam name="T">The type of the <see cref="Enum"/>.</typeparam>
/// <param name="value">The <see cref="string"/> value to parse</param>
/// <param name="value">The <see cref="string"/> value to parse.</param>
/// <param name="ignoreCase">Whether or not to ignore casing.</param>
/// <returns>The <see cref="Enum"/> value corresponding to the <see cref="string"/></returns>
/// <returns>The <see cref="Enum"/> value corresponding to the <see cref="string"/>.</returns>
public static T EnumParse<T>(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);
}

View File

@ -11,19 +11,20 @@
/// Returns the next value in an <see cref="Enum"/> using the specified value as a starting point.
/// </summary>
/// <typeparam name="T">An <see cref="Enum"/>.</typeparam>
/// <param name="src">An <see cref="Enum"/> value</param>
/// <param name="src">An <see cref="Enum"/> value.</param>
/// <param name="wrap">Optional. Whether or not to wrap to the to the start of the enum. Defaults to
/// true.</param>
/// <returns>Returns a <see cref="T"/> value.</returns>
public static T Next<T>(this T src, bool wrap = true) where T : struct
public static T Next<T>(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 <see cref="Enum"/> using the specified value as a starting point.
/// </summary>
/// <typeparam name="T">An <see cref="Enum"/>.</typeparam>
/// <param name="src">An <see cref="Enum"/> value</param>
/// <param name="src">An <see cref="Enum"/> value.</param>
/// <param name="wrap">Optional. Whether or not to wrap to the to the end of the enum. Defaults to
/// true.</param>
/// <returns>Returns a <see cref="T"/> value.</returns>
public static T Previous<T>(this T src, bool wrap = true) where T : struct
public static T Previous<T>(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];
}
}

View File

@ -4,6 +4,9 @@
using System.Diagnostics;
using System.Text.RegularExpressions;
/// <summary>
/// Represents a class which contains a <see cref="string"/> parser which converts into <see cref="TimeSpan"/>.
/// </summary>
public static class TimeSpanParser
{
/// <summary>
@ -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;