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;
/// <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)
{
/// <summary>
/// Gets or sets the radius of the circle.
/// </summary>
public double Radius { get; set; } = radius;
/// <summary>
/// Gets the diameter of the circle.
/// </summary>
public double Diameter => Radius * 2;
/// <summary>
/// Gets the circumference of the circle.
/// </summary>
public double Circumference => 2 * Math.PI * Radius;
/// <summary>
/// Gets the area of the circle.
/// </summary>
public double Area => Math.PI * Math.Pow(Radius, 2);
}
@@ -1,12 +1,37 @@
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)
{
/// <summary>
/// Gets or sets the length of the major axis.
/// </summary>
public double MajorAxis { get; set; } = majorAxis;
/// <summary>
/// Gets or sets the length of the minor axis.
/// </summary>
public double MinorAxis { get; set; } = minorAxis;
/// <summary>
/// Gets the area of the ellipse.
/// </summary>
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))));
/// <summary>
/// Gets a value indicating whether the ellipse is a circle.
/// </summary>
public bool IsCircle => MajorAxis == MinorAxis;
}
+19 -9
View File
@@ -1,42 +1,52 @@
namespace CuteUtils.FluentMath.Shapes;
/// <summary>
/// Represents a rectangle
/// Represents a rectangle shape.
/// </summary>
/// <remarks>
/// Creates a new rectangle instance
/// Initializes a new instance of the <see cref="Rectangle"/> class with the specified length and width.
/// </remarks>
/// <param name="length">The length of the rectangle</param>
/// <param name="width">The width of the rectangle</param>
/// <param name="length">The length of the rectangle.</param>
/// <param name="width">The width of the rectangle.</param>
public class Rectangle(double length, double width)
{
/// <summary>
/// The length of the <see cref="Rectangle"/>
/// Gets or sets the length of the rectangle.
/// </summary>
public double Length { get; set; } = length;
/// <summary>
/// The width of the <see cref="Rectangle"/>
/// Gets or sets the width of the rectangle.
/// </summary>
public double Width { get; set; } = width;
/// <summary>
/// The diagonal of the <see cref="Rectangle"/>
/// Gets the diagonal length of the rectangle.
/// </summary>
public double Diagonal => Math.Sqrt(Math.Pow(Length, 2) + Math.Pow(Width, 2));
/// <summary>
/// The area of the <see cref="Rectangle"/>
/// Gets the area of the rectangle.
/// </summary>
public double Area => Length * Width;
/// <summary>
/// The perimeter of the <see cref="Rectangle"/>
/// Gets the perimeter of the rectangle.
/// </summary>
public double Perimeter => (Length * 2) + (Width * 2);
/// <summary>
/// Gets a value indicating whether the rectangle is a square.
/// </summary>
public bool IsSquare => Length == Width;
/// <summary>
/// Gets a value indicating whether the rectangle is a rectangle (not a square).
/// </summary>
public bool IsRectangle => !IsSquare;
/// <summary>
/// Gets a value indicating whether the rectangle has a golden ratio.
/// </summary>
public bool IsGolden => Length / Width == 1.61803398875;
}
@@ -1,11 +1,34 @@
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)
{
/// <summary>
/// Gets or sets the length of side A.
/// </summary>
public double SideA { get; set; } = sideA;
/// <summary>
/// Gets or sets the length of side B.
/// </summary>
public double SideB { get; set; } = sideB;
/// <summary>
/// Gets or sets the length of side C.
/// </summary>
public double SideC { get; set; } = sideC;
/// <summary>
/// Gets the area of the triangle.
/// </summary>
public double Area
{
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;
/// <summary>
/// Gets a value indicating whether the triangle is right-angled.
/// </summary>
public bool IsRightAngled
{
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;
/// <summary>
/// Gets a value indicating whether the triangle is isosceles.
/// </summary>
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;
}
+47
View File
@@ -3,8 +3,16 @@ using System.Reflection;
namespace CuteUtils.Reflection;
/// <summary>
/// Provides utility methods for converting objects to and from dynamic DTOs.
/// </summary>
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)
{
ExpandoObject dto = new ExpandoObject();
@@ -24,6 +32,13 @@ public static class DynDto
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)
{
ArgumentNullException.ThrowIfNull(dto);
@@ -46,11 +61,24 @@ public static class DynDto
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()
{
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)
{
ArgumentNullException.ThrowIfNull(data);
@@ -75,6 +103,13 @@ public static class DynDto
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)
{
ArgumentNullException.ThrowIfNull(dto);
@@ -96,11 +131,23 @@ public static class DynDto
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()
{
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()
{
return FromDto(dto, new T());
@@ -1,6 +1,17 @@
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)]
public class DynDtoNameAttribute(string name) : Attribute
{
/// <summary>
/// Gets or sets the dynamic DTO name.
/// </summary>
public string Name { get; set; } = name;
}
}
@@ -3,16 +3,16 @@
namespace CuteUtils.Reflection;
/// <summary>
/// Reflection class
/// Provides extension methods for reflection operations.
/// </summary>
public static class ReflectionExtentions
{
/// <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>
/// <typeparam name="T"></typeparam>
/// <param name="obj"></param>
/// <returns></returns>
/// <typeparam name="T">The type of the new instance.</typeparam>
/// <param name="obj">The source object.</param>
/// <returns>A new instance of the specified type with copied properties.</returns>
public static T CopyProperties<T>(this object obj) where T : new()
{
T newObj = new T();
@@ -33,12 +33,13 @@ public static class ReflectionExtentions
}
/// <summary>
/// Copies all properties of an object to a different one.
/// Copies the properties from the source object to the specified target object.
/// </summary>
/// <typeparam name="T"></typeparam>
/// <param name="obj"></param>
/// <param name="newObj"></param>
/// <returns></returns>
/// <typeparam name="T">The type of the target object.</typeparam>
/// <param name="obj">The source object.</param>
/// <param name="newObj">The target object.</param>
/// <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)
{
ArgumentNullException.ThrowIfNull(newObj);