Core - Added XML comments to all remaining public members/methods

Core - Refactored a lot of code for nullable reference types
This commit is contained in:
Robert committed 2020-11-16 20:16:06 +01:00
1 parent 61fc96742d
commit a3cd32f6c4
107 files changed
+1150 -649

No files matched your search

@@ -2,7 +2,7 @@
namespace Artemis.Core
{
public static class DirectoryInfoExtensions
internal static class DirectoryInfoExtensions
{
public static void CopyFilesRecursively(this DirectoryInfo source, DirectoryInfo target)
{
@@ -3,8 +3,16 @@ using System.Runtime.CompilerServices;
namespace Artemis.Core
{
/// <summary>
/// A static class providing <see cref="double" /> extensions
/// </summary>
public static class DoubleExtensions
{
/// <summary>
/// Rounds the provided number away to zero and casts the result to an <see cref="int" />
/// </summary>
/// <param name="number">The number to round</param>
/// <returns>The rounded number as an integer</returns>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static int RoundToInt(this double number)
{
@@ -1,9 +1,19 @@
using System;
using System.Runtime.CompilerServices;
namespace Artemis.Core
{
/// <summary>
/// A static class providing <see cref="float" /> extensions
/// </summary>
public static class FloatExtensions
{
/// <summary>
/// Rounds the provided number away to zero and casts the result to an <see cref="int" />
/// </summary>
/// <param name="number">The number to round</param>
/// <returns>The rounded number as an integer</returns>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static int RoundToInt(this float number)
{
return (int) Math.Round(number, MidpointRounding.AwayFromZero);
@@ -24,6 +24,10 @@ using System.Collections.Generic;
namespace Artemis.Core
{
/// <summary>
/// A static class providing <see cref="IEnumerable{T}" /> extensions
/// </summary>
// ReSharper disable once InconsistentNaming
public static class IEnumerableExtensions
{
/// <summary>
@@ -46,7 +50,7 @@ namespace Artemis.Core
public static IEnumerable<TSource> DistinctBy<TSource, TKey>(this IEnumerable<TSource> source,
Func<TSource, TKey> keySelector)
{
return source.DistinctBy(keySelector, null);
return source.DistinctBy(keySelector, null!);
}
/// <summary>
@@ -5,8 +5,16 @@ using System.Text;
namespace Artemis.Core
{
/// <summary>
/// A static class providing <see cref="Process" /> extensions
/// </summary>
public static class ProcessExtensions
{
/// <summary>
/// Gets the file name of the given process
/// </summary>
/// <param name="p">The process</param>
/// <returns>The filename of the given process</returns>
public static string GetProcessFilename(this Process p)
{
int capacity = 2000;
@@ -17,7 +25,7 @@ namespace Artemis.Core
return builder.ToString();
}
[DllImport("kernel32.dll")]
[DllImport("kernel32.dll", CharSet = CharSet.Unicode)]
private static extern bool QueryFullProcessImageName([In] IntPtr hProcess, [In] int dwFlags, [Out] StringBuilder lpExeName, ref int lpdwSize);
[DllImport("kernel32.dll")]
@@ -3,7 +3,7 @@ using RGB.NET.Core;
namespace Artemis.Core
{
public static class RgbDeviceExtensions
internal static class RgbDeviceExtensions
{
public static string GetDeviceIdentifier(this IRGBDevice rgbDevice)
{
@@ -1,18 +0,0 @@
using RGB.NET.Core;
using SkiaSharp;
namespace Artemis.Core
{
public static class RgbRectangleExtensions
{
public static SKRect ToSKRect(this Rectangle rectangle, double scale)
{
return SKRect.Create(
(rectangle.Location.X * scale).RoundToInt(),
(rectangle.Location.Y * scale).RoundToInt(),
(rectangle.Size.Width * scale).RoundToInt(),
(rectangle.Size.Height * scale).RoundToInt()
);
}
}
}
@@ -4,14 +4,28 @@ using SkiaSharp;
namespace Artemis.Core
{
// ReSharper disable once InconsistentNaming - I didn't come up with SKColor
/// <summary>
/// A static class providing <see cref="SKColor" /> extensions
/// </summary>
public static class SKColorExtensions
{
/// <summary>
/// Converts hte SKColor to an RGB.NET color
/// </summary>
/// <param name="color">The color to convert</param>
/// <returns>The RGB.NET color</returns>
public static Color ToRgbColor(this SKColor color)
{
return new Color(color.Alpha, color.Red, color.Green, color.Blue);
}
/// <summary>
/// Interpolates a color between the <paramref name="from" /> and <paramref name="to" /> color.
/// </summary>
/// <param name="from">The first color</param>
/// <param name="to">The second color</param>
/// <param name="progress">A value between 0 and 1</param>
/// <returns>The interpolated color</returns>
public static SKColor Interpolate(this SKColor from, SKColor to, float progress)
{
int redDiff = to.Red - from.Red;
@@ -27,6 +41,12 @@ namespace Artemis.Core
);
}
/// <summary>
/// Adds the two colors together
/// </summary>
/// <param name="a">The first color</param>
/// <param name="b">The second color</param>
/// <returns>The sum of the two colors</returns>
public static SKColor Sum(this SKColor a, SKColor b)
{
return new SKColor(
+28 -4
View File
@@ -6,6 +6,9 @@ using Humanizer;
namespace Artemis.Core
{
/// <summary>
/// A static class providing <see cref="Type" /> extensions
/// </summary>
public static class TypeExtensions
{
private static readonly Dictionary<Type, List<Type>> PrimitiveTypeConversions = new Dictionary<Type, List<Type>>
@@ -40,6 +43,12 @@ namespace Artemis.Core
{typeof(string), "string"}
};
/// <summary>
/// Determines whether the provided type is of a specified generic type
/// </summary>
/// <param name="type">The type to check</param>
/// <param name="genericType">The generic type to match</param>
/// <returns>True if the <paramref name="type" /> is generic and of generic type <paramref name="genericType" /></returns>
public static bool IsGenericType(this Type type, Type genericType)
{
if (type == null)
@@ -48,11 +57,21 @@ namespace Artemis.Core
return type.BaseType?.GetGenericTypeDefinition() == genericType;
}
public static bool IsStruct(this Type source)
/// <summary>
/// Determines whether the provided type is a struct
/// </summary>
/// <param name="type">The type to check</param>
/// <returns><see langword="true" /> if the type is a struct, otherwise <see langword="false" /></returns>
public static bool IsStruct(this Type type)
{
return source.IsValueType && !source.IsPrimitive && !source.IsEnum;
return type.IsValueType && !type.IsPrimitive && !type.IsEnum;
}
/// <summary>
/// Determines whether the provided type is any kind of numeric type
/// </summary>
/// <param name="type">The type to check</param>
/// <returns><see langword="true" /> if the type a numeric type, otherwise <see langword="false" /></returns>
public static bool TypeIsNumber(this Type type)
{
return type == typeof(sbyte)
@@ -68,6 +87,11 @@ namespace Artemis.Core
|| type == typeof(decimal);
}
/// <summary>
/// Determines whether the provided value is any kind of numeric type
/// </summary>
/// <param name="value">The value to check</param>
/// <returns><see langword="true" /> if the value is of a numeric type, otherwise <see langword="false" /></returns>
public static bool IsNumber(this object value)
{
return value is sbyte
@@ -126,7 +150,7 @@ namespace Artemis.Core
/// <summary>
/// Returns the default value of the given type
/// </summary>
public static object GetDefault(this Type type)
public static object? GetDefault(this Type type)
{
return type.IsValueType ? Activator.CreateInstance(type) : null;
}
@@ -157,7 +181,7 @@ namespace Artemis.Core
if (type.IsGenericType && type.GetGenericTypeDefinition() == typeof(IEnumerable<>))
return type.GenericTypeArguments[0];
Type enumerableType = type.GetInterfaces().FirstOrDefault(x =>
Type? enumerableType = type.GetInterfaces().FirstOrDefault(x =>
x.IsGenericType &&
x.GetGenericTypeDefinition() == typeof(IEnumerable<>));