Add missing xml docs

This commit is contained in:
Stone_Red
2024-03-19 19:54:21 +01:00
parent 80b5cc5109
commit 86b510faef
7 changed files with 171 additions and 20 deletions
+19
View File
@@ -1,12 +1,31 @@
namespace CuteUtils.FluentMath.Shapes; namespace CuteUtils.FluentMath.Shapes;
/// <summary>
/// Represents a circle shape.
/// </summary>
/// <remarks>
/// Initializes a new instance of the <see cref="Circle"/> class with the specified radius.
/// </remarks>
/// <param name="radius">The radius of the circle.</param>
public class Circle(double radius) public class Circle(double radius)
{ {
/// <summary>
/// Gets or sets the radius of the circle.
/// </summary>
public double Radius { get; set; } = radius; public double Radius { get; set; } = radius;
/// <summary>
/// Gets the diameter of the circle.
/// </summary>
public double Diameter => Radius * 2; public double Diameter => Radius * 2;
/// <summary>
/// Gets the circumference of the circle.
/// </summary>
public double Circumference => 2 * Math.PI * Radius; public double Circumference => 2 * Math.PI * Radius;
/// <summary>
/// Gets the area of the circle.
/// </summary>
public double Area => Math.PI * Math.Pow(Radius, 2); public double Area => Math.PI * Math.Pow(Radius, 2);
} }
@@ -1,12 +1,37 @@
namespace CuteUtils.FluentMath.Shapes; namespace CuteUtils.FluentMath.Shapes;
/// <summary>
/// Represents an ellipse shape.
/// </summary>
/// <remarks>
/// Initializes a new instance of the <see cref="Ellipse"/> class with the specified major and minor axes.
/// </remarks>
/// <param name="majorAxis">The length of the major axis.</param>
/// <param name="minorAxis">The length of the minor axis.</param>
public class Ellipse(double majorAxis, double minorAxis) public class Ellipse(double majorAxis, double minorAxis)
{ {
/// <summary>
/// Gets or sets the length of the major axis.
/// </summary>
public double MajorAxis { get; set; } = majorAxis; public double MajorAxis { get; set; } = majorAxis;
/// <summary>
/// Gets or sets the length of the minor axis.
/// </summary>
public double MinorAxis { get; set; } = minorAxis; public double MinorAxis { get; set; } = minorAxis;
/// <summary>
/// Gets the area of the ellipse.
/// </summary>
public double Area => Math.PI * MajorAxis * MinorAxis; public double Area => Math.PI * MajorAxis * MinorAxis;
/// <summary>
/// Gets the circumference of the ellipse.
/// </summary>
public double Circumference => Math.PI * ((3 * (MajorAxis + MinorAxis)) - Math.Sqrt(((3 * MajorAxis) + MinorAxis) * (MajorAxis + (3 * MinorAxis)))); public double Circumference => Math.PI * ((3 * (MajorAxis + MinorAxis)) - Math.Sqrt(((3 * MajorAxis) + MinorAxis) * (MajorAxis + (3 * MinorAxis))));
/// <summary>
/// Gets a value indicating whether the ellipse is a circle.
/// </summary>
public bool IsCircle => MajorAxis == MinorAxis; public bool IsCircle => MajorAxis == MinorAxis;
} }
+19 -9
View File
@@ -1,42 +1,52 @@
namespace CuteUtils.FluentMath.Shapes; namespace CuteUtils.FluentMath.Shapes;
/// <summary> /// <summary>
/// Represents a rectangle /// Represents a rectangle shape.
/// </summary> /// </summary>
/// <remarks> /// <remarks>
/// Creates a new rectangle instance /// Initializes a new instance of the <see cref="Rectangle"/> class with the specified length and width.
/// </remarks> /// </remarks>
/// <param name="length">The length of the rectangle</param> /// <param name="length">The length of the rectangle.</param>
/// <param name="width">The width of the rectangle</param> /// <param name="width">The width of the rectangle.</param>
public class Rectangle(double length, double width) public class Rectangle(double length, double width)
{ {
/// <summary> /// <summary>
/// The length of the <see cref="Rectangle"/> /// Gets or sets the length of the rectangle.
/// </summary> /// </summary>
public double Length { get; set; } = length; public double Length { get; set; } = length;
/// <summary> /// <summary>
/// The width of the <see cref="Rectangle"/> /// Gets or sets the width of the rectangle.
/// </summary> /// </summary>
public double Width { get; set; } = width; public double Width { get; set; } = width;
/// <summary> /// <summary>
/// The diagonal of the <see cref="Rectangle"/> /// Gets the diagonal length of the rectangle.
/// </summary> /// </summary>
public double Diagonal => Math.Sqrt(Math.Pow(Length, 2) + Math.Pow(Width, 2)); public double Diagonal => Math.Sqrt(Math.Pow(Length, 2) + Math.Pow(Width, 2));
/// <summary> /// <summary>
/// The area of the <see cref="Rectangle"/> /// Gets the area of the rectangle.
/// </summary> /// </summary>
public double Area => Length * Width; public double Area => Length * Width;
/// <summary> /// <summary>
/// The perimeter of the <see cref="Rectangle"/> /// Gets the perimeter of the rectangle.
/// </summary> /// </summary>
public double Perimeter => (Length * 2) + (Width * 2); public double Perimeter => (Length * 2) + (Width * 2);
/// <summary>
/// Gets a value indicating whether the rectangle is a square.
/// </summary>
public bool IsSquare => Length == Width; public bool IsSquare => Length == Width;
/// <summary>
/// Gets a value indicating whether the rectangle is a rectangle (not a square).
/// </summary>
public bool IsRectangle => !IsSquare; public bool IsRectangle => !IsSquare;
/// <summary>
/// Gets a value indicating whether the rectangle has a golden ratio.
/// </summary>
public bool IsGolden => Length / Width == 1.61803398875; public bool IsGolden => Length / Width == 1.61803398875;
} }
@@ -1,11 +1,34 @@
namespace CuteUtils.FluentMath.Shapes; namespace CuteUtils.FluentMath.Shapes;
/// <summary>
/// Represents a triangle with three sides.
/// </summary>
/// <remarks>
/// Initializes a new instance of the <see cref="Triangle"/> class with the specified side lengths.
/// </remarks>
/// <param name="sideA">The length of side A.</param>
/// <param name="sideB">The length of side B.</param>
/// <param name="sideC">The length of side C.</param>
public class Triangle(double sideA, double sideB, double sideC) public class Triangle(double sideA, double sideB, double sideC)
{ {
/// <summary>
/// Gets or sets the length of side A.
/// </summary>
public double SideA { get; set; } = sideA; public double SideA { get; set; } = sideA;
/// <summary>
/// Gets or sets the length of side B.
/// </summary>
public double SideB { get; set; } = sideB; public double SideB { get; set; } = sideB;
/// <summary>
/// Gets or sets the length of side C.
/// </summary>
public double SideC { get; set; } = sideC; public double SideC { get; set; } = sideC;
/// <summary>
/// Gets the area of the triangle.
/// </summary>
public double Area public double Area
{ {
get get
@@ -15,8 +38,14 @@ public class Triangle(double sideA, double sideB, double sideC)
} }
} }
/// <summary>
/// Gets the perimeter of the triangle.
/// </summary>
public double Perimeter => SideA + SideB + SideC; public double Perimeter => SideA + SideB + SideC;
/// <summary>
/// Gets a value indicating whether the triangle is right-angled.
/// </summary>
public bool IsRightAngled public bool IsRightAngled
{ {
get get
@@ -27,9 +56,18 @@ public class Triangle(double sideA, double sideB, double sideC)
} }
} }
/// <summary>
/// Gets a value indicating whether the triangle is equilateral.
/// </summary>
public bool IsEquilateral => SideA == SideB && SideB == SideC; public bool IsEquilateral => SideA == SideB && SideB == SideC;
/// <summary>
/// Gets a value indicating whether the triangle is isosceles.
/// </summary>
public bool IsIsosceles => SideA == SideB || SideB == SideC || SideA == SideC; public bool IsIsosceles => SideA == SideB || SideB == SideC || SideA == SideC;
/// <summary>
/// Gets a value indicating whether the triangle is scalene.
/// </summary>
public bool IsScalene => !IsEquilateral && !IsIsosceles; public bool IsScalene => !IsEquilateral && !IsIsosceles;
} }
+47
View File
@@ -3,8 +3,16 @@ using System.Reflection;
namespace CuteUtils.Reflection; namespace CuteUtils.Reflection;
/// <summary>
/// Provides utility methods for converting objects to and from dynamic DTOs.
/// </summary>
public static class DynDto public static class DynDto
{ {
/// <summary>
/// Converts an object to a dynamic DTO.
/// </summary>
/// <param name="data">The object to convert.</param>
/// <returns>The dynamic DTO.</returns>
public static ExpandoObject ToDto(this object data) public static ExpandoObject ToDto(this object data)
{ {
ExpandoObject dto = new ExpandoObject(); ExpandoObject dto = new ExpandoObject();
@@ -24,6 +32,13 @@ public static class DynDto
return dto; return dto;
} }
/// <summary>
/// Converts an object to a specified type of DTO.
/// </summary>
/// <typeparam name="T">The type of DTO.</typeparam>
/// <param name="data">The object to convert.</param>
/// <param name="dto">The DTO instance to populate.</param>
/// <returns>The populated DTO.</returns>
public static T ToDto<T>(this object data, T dto) public static T ToDto<T>(this object data, T dto)
{ {
ArgumentNullException.ThrowIfNull(dto); ArgumentNullException.ThrowIfNull(dto);
@@ -46,11 +61,24 @@ public static class DynDto
return dto; return dto;
} }
/// <summary>
/// Converts an object to a new instance of a specified type of DTO.
/// </summary>
/// <typeparam name="T">The type of DTO.</typeparam>
/// <param name="data">The object to convert.</param>
/// <returns>The new instance of the DTO.</returns>
public static T ToDto<T>(this object data) where T : new() public static T ToDto<T>(this object data) where T : new()
{ {
return ToDto(data, new T()); return ToDto(data, new T());
} }
/// <summary>
/// Converts a dynamic DTO to an object.
/// </summary>
/// <typeparam name="T">The type of object.</typeparam>
/// <param name="dto">The dynamic DTO.</param>
/// <param name="data">The object instance to populate.</param>
/// <returns>The populated object.</returns>
public static T FromDto<T>(this object dto, T data) public static T FromDto<T>(this object dto, T data)
{ {
ArgumentNullException.ThrowIfNull(data); ArgumentNullException.ThrowIfNull(data);
@@ -75,6 +103,13 @@ public static class DynDto
return data; return data;
} }
/// <summary>
/// Converts a dynamic DTO to an object.
/// </summary>
/// <typeparam name="T">The type of object.</typeparam>
/// <param name="dto">The dynamic DTO.</param>
/// <param name="data">The new instance of the object.</param>
/// <returns>The populated object.</returns>
public static T FromDto<T>(this ExpandoObject dto, T data) public static T FromDto<T>(this ExpandoObject dto, T data)
{ {
ArgumentNullException.ThrowIfNull(dto); ArgumentNullException.ThrowIfNull(dto);
@@ -96,11 +131,23 @@ public static class DynDto
return data; return data;
} }
/// <summary>
/// Converts a dynamic DTO to a new instance of an object.
/// </summary>
/// <typeparam name="T">The type of object.</typeparam>
/// <param name="dto">The dynamic DTO.</param>
/// <returns>The new instance of the object.</returns>
public static T FromDto<T>(this object dto) where T : new() public static T FromDto<T>(this object dto) where T : new()
{ {
return FromDto(dto, new T()); return FromDto(dto, new T());
} }
/// <summary>
/// Converts a dynamic DTO to a new instance of an object.
/// </summary>
/// <typeparam name="T">The type of object.</typeparam>
/// <param name="dto">The dynamic DTO.</param>
/// <returns>The new instance of the object.</returns>
public static T FromDto<T>(this ExpandoObject dto) where T : new() public static T FromDto<T>(this ExpandoObject dto) where T : new()
{ {
return FromDto(dto, new T()); return FromDto(dto, new T());
@@ -1,6 +1,17 @@
namespace CuteUtils.Reflection; namespace CuteUtils.Reflection;
/// <summary>
/// Represents an attribute that specifies the dynamic DTO name for a property.
/// </summary>
/// <remarks>
/// Initializes a new instance of the <see cref="DynDtoNameAttribute"/> class with the specified name.
/// </remarks>
/// <param name="name">The dynamic DTO name.</param>
[AttributeUsage(AttributeTargets.Property, AllowMultiple = false)] [AttributeUsage(AttributeTargets.Property, AllowMultiple = false)]
public class DynDtoNameAttribute(string name) : Attribute public class DynDtoNameAttribute(string name) : Attribute
{ {
/// <summary>
/// Gets or sets the dynamic DTO name.
/// </summary>
public string Name { get; set; } = name; public string Name { get; set; } = name;
} }
@@ -3,16 +3,16 @@
namespace CuteUtils.Reflection; namespace CuteUtils.Reflection;
/// <summary> /// <summary>
/// Reflection class /// Provides extension methods for reflection operations.
/// </summary> /// </summary>
public static class ReflectionExtentions public static class ReflectionExtentions
{ {
/// <summary> /// <summary>
/// Copies all properties of an object to a new one. /// Creates a new instance of the specified type and copies the properties from the source object to the new instance.
/// </summary> /// </summary>
/// <typeparam name="T"></typeparam> /// <typeparam name="T">The type of the new instance.</typeparam>
/// <param name="obj"></param> /// <param name="obj">The source object.</param>
/// <returns></returns> /// <returns>A new instance of the specified type with copied properties.</returns>
public static T CopyProperties<T>(this object obj) where T : new() public static T CopyProperties<T>(this object obj) where T : new()
{ {
T newObj = new T(); T newObj = new T();
@@ -33,12 +33,13 @@ public static class ReflectionExtentions
} }
/// <summary> /// <summary>
/// Copies all properties of an object to a different one. /// Copies the properties from the source object to the specified target object.
/// </summary> /// </summary>
/// <typeparam name="T"></typeparam> /// <typeparam name="T">The type of the target object.</typeparam>
/// <param name="obj"></param> /// <param name="obj">The source object.</param>
/// <param name="newObj"></param> /// <param name="newObj">The target object.</param>
/// <returns></returns> /// <returns>The target object with copied properties.</returns>
/// <exception cref="ArgumentNullException">Thrown when the target object is null.</exception>
public static T CopyProperties<T>(this object obj, T newObj) public static T CopyProperties<T>(this object obj, T newObj)
{ {
ArgumentNullException.ThrowIfNull(newObj); ArgumentNullException.ThrowIfNull(newObj);