Skip to content

Commit 6ae371c

Browse files
committed
Added parsing, fixed xml comments, updated TFMs
1 parent d93764e commit 6ae371c

29 files changed

+1771
-1238
lines changed

.github/workflows/dotnet-core.yml

+2-2
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ jobs:
3333
- name: Setup .NET Core
3434
uses: actions/setup-dotnet@v1
3535
with:
36-
dotnet-version: 5.0.x
36+
dotnet-version: 6.0.x
3737
- name: Restore
3838
run: dotnet restore
3939
- name: Build
@@ -73,7 +73,7 @@ jobs:
7373
- name: Setup .NET Core
7474
uses: actions/setup-dotnet@v1
7575
with:
76-
dotnet-version: 5.0.x
76+
dotnet-version: 6.0.x
7777
- name: Create Release NuGet package
7878
run: |
7979
arrTag=(${GITHUB_REF//\// })

Directory.Build.props

+2-21
Original file line numberDiff line numberDiff line change
@@ -41,17 +41,16 @@
4141
</PropertyGroup>
4242

4343
<PropertyGroup>
44-
<LangVersion>9.0</LangVersion>
44+
<LangVersion>10.0</LangVersion>
4545
</PropertyGroup>
4646

47+
4748
<!-- Define target framework specific constants.
4849
https://apisof.net/
4950
+===================+=======+==========+=====================+=============+=================+====================+==============+=========+============|===============|
5051
| SUPPORTS | MATHF | HASHCODE | EXTENDED_INTRINSICS | SPAN_STREAM | ENCODING_STRING | RUNTIME_INTRINSICS | CODECOVERAGE | HOTPATH | CREATESPAN | BITOPERATIONS |
5152
+===================+=======+==========+=====================+=============+=================+====================+==============+=========|============|===============|
5253
| >=netcoreapp3.1 | Y | Y | Y | Y | Y | Y | Y | Y | Y | Y |
53-
| netcoreapp2.1 | Y | Y | Y | Y | Y | N | Y | N | Y | N |
54-
| netcoreapp2.0 | Y | N | N | N | N | N | Y | N | Y | N |
5554
| netstandard2.1 | Y | Y | N | Y | Y | N | Y | N | Y | N |
5655
| netstandard2.0 | N | N | N | N | N | N | Y | N | N | N |
5756
| netstandard1.3 | N | N | N | N | N | N | N | N | N | N |
@@ -81,24 +80,6 @@
8180
<DefineConstants>$(DefineConstants);SUPPORTS_CREATESPAN</DefineConstants>
8281
</PropertyGroup>
8382
</When>
84-
<When Condition="'$(TargetFramework)' == 'netcoreapp2.0'">
85-
<PropertyGroup>
86-
<DefineConstants>$(DefineConstants);SUPPORTS_MATHF</DefineConstants>
87-
<DefineConstants>$(DefineConstants);SUPPORTS_CODECOVERAGE</DefineConstants>
88-
<DefineConstants>$(DefineConstants);SUPPORTS_CREATESPAN</DefineConstants>
89-
</PropertyGroup>
90-
</When>
91-
<When Condition="'$(TargetFramework)' == 'netcoreapp2.1'">
92-
<PropertyGroup>
93-
<DefineConstants>$(DefineConstants);SUPPORTS_MATHF</DefineConstants>
94-
<DefineConstants>$(DefineConstants);SUPPORTS_HASHCODE</DefineConstants>
95-
<DefineConstants>$(DefineConstants);SUPPORTS_EXTENDED_INTRINSICS</DefineConstants>
96-
<DefineConstants>$(DefineConstants);SUPPORTS_SPAN_STREAM</DefineConstants>
97-
<DefineConstants>$(DefineConstants);SUPPORTS_ENCODING_STRING</DefineConstants>
98-
<DefineConstants>$(DefineConstants);SUPPORTS_CODECOVERAGE</DefineConstants>
99-
<DefineConstants>$(DefineConstants);SUPPORTS_CREATESPAN</DefineConstants>
100-
</PropertyGroup>
101-
</When>
10283
<When Condition="$([MSBuild]::IsTargetFrameworkCompatible('$(TargetFramework)','netcoreapp3.1'))">
10384
<!--NETCORE 3.1. NET5.0, and future versions will fallback to this as the closest target.-->
10485
<PropertyGroup>

Directory.Build.targets

-3
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,6 @@
77
</PropertyGroup>
88

99
<ItemGroup>
10-
<PackageReference Update="Aspose.PDF" Version="20.1.0" />
11-
<PackageReference Update="iTextSharp" Version="5.5.13.1" NoWarn="NU1701" />
12-
<PackageReference Update="SixLabors.ImageSharp.Drawing" Version="1.0.0-beta0007" />
1310
<PackageReference Update="xunit.assert" Version="2.4.1" />
1411
</ItemGroup>
1512

LICENSE

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
MIT License
22

3-
Copyright (c) 2020 Gerard Gunnewijk
3+
Copyright (c) 2022 Gerard Gunnewijk
44

55
Permission is hereby granted, free of charge, to any person obtaining a copy
66
of this software and associated documentation files (the "Software"), to deal

src/Directory.Build.props

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
<Project>
33

44
<PropertyGroup>
5-
<TargetFrameworks>net452;netcoreapp2.1;netcoreapp3.1;netstandard1.6;netstandard2.0;netstandard2.1;net5.0</TargetFrameworks>
5+
<TargetFrameworks>net48;netcoreapp3.1;netstandard1.6;netstandard2.0;netstandard2.1;net5.0;net6.0</TargetFrameworks>
66
<MSBuildAllProjects>$(MSBuildAllProjects);$(MSBuildThisFileDirectory)..\Directory.Build.props</MSBuildAllProjects>
77
<SynercodingProjectCategory>src</SynercodingProjectCategory>
88
</PropertyGroup>
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,16 @@
1-
namespace Synercoding.Primitives.Abstract
1+
namespace Synercoding.Primitives.Abstract;
2+
3+
/// <summary>
4+
/// Enable converting types between different <see cref="Unit"/>s.
5+
/// </summary>
6+
/// <typeparam name="T">The convertable type.</typeparam>
7+
/// <remarks>The <typeparamref name="T"/> should be the implementing type.</remarks>
8+
public interface IConvertable<T>
29
{
310
/// <summary>
4-
/// Enable converting types between different units
11+
/// Convert this type to the same type but with a different <see cref="Unit"/>.
512
/// </summary>
6-
/// <typeparam name="T">The convertable type</typeparam>
7-
/// <remarks>The <typeparamref name="T"/> should be the implementing type.</remarks>
8-
public interface IConvertable<T>
9-
{
10-
/// <summary>
11-
/// Convert this type to the same type but with a different unit.
12-
/// </summary>
13-
/// <param name="unit">The target type.</param>
14-
/// <returns>A new value with different unit.</returns>
15-
T ConvertTo(Unit unit);
16-
}
13+
/// <param name="unit">The target <see cref="Unit"/>.</param>
14+
/// <returns>A new <typeparamref name="T"/> with different <see cref="Unit"/>.</returns>
15+
T ConvertTo(Unit unit);
1716
}
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,16 @@
1-
namespace Synercoding.Primitives.Extensions
1+
namespace Synercoding.Primitives.Extensions;
2+
3+
/// <summary>
4+
/// Extensions methods for <see cref="Point"/>.
5+
/// </summary>
6+
public static class PointExtensions
27
{
38
/// <summary>
4-
/// Extensions methods for <see cref="Point"/>
9+
/// Get the raw values representing this <see cref="Point"/> in a provided <see cref="Unit"/>.
510
/// </summary>
6-
public static class PointExtensions
7-
{
8-
/// <summary>
9-
/// Get the raw values representing this Point in a provided unit
10-
/// </summary>
11-
/// <param name="point">The point to get in raw format</param>
12-
/// <param name="unit">The unit to get the result in.</param>
13-
/// <returns>A tuple representing the raw values.</returns>
14-
public static (double X, double Y) AsRaw(this Point point, Unit unit)
15-
=> (point.X.AsRaw(unit), point.Y.AsRaw(unit));
16-
}
11+
/// <param name="point">The <see cref="Point"/> to get in raw format.</param>
12+
/// <param name="unit">The <see cref="Unit"/> to get the result in.</param>
13+
/// <returns>A tuple representing the raw values.</returns>
14+
public static (double X, double Y) AsRaw(this Point point, Unit unit)
15+
=> (point.X.AsRaw(unit), point.Y.AsRaw(unit));
1716
}
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,42 @@
1-
namespace Synercoding.Primitives.Extensions
1+
namespace Synercoding.Primitives.Extensions;
2+
3+
/// <summary>
4+
/// Extension class for <seealso cref="Rectangle"/>.
5+
/// </summary>
6+
public static class RectangleExtensions
27
{
38
/// <summary>
4-
/// Extension class for <seealso cref="Rectangle"/>
9+
/// Contract a given <see cref="Rectangle"/> (make smaller).
10+
/// </summary>
11+
/// <param name="rectangle">The <see cref="Rectangle"/> to contract.</param>
12+
/// <param name="spacing">The amount of <see cref="Spacing"/> to contract on the sides.</param>
13+
/// <returns>A new contacted <see cref="Rectangle"/>.</returns>
14+
public static Rectangle Contract(this Rectangle rectangle, Spacing spacing)
15+
=> new Rectangle(
16+
llx: rectangle.LLX + spacing.Left,
17+
lly: rectangle.LLY + spacing.Bottom,
18+
urx: rectangle.URX - spacing.Right,
19+
ury: rectangle.URY - spacing.Top);
20+
21+
/// <summary>
22+
/// Expand a given <see cref="Rectangle"/> (make bigger).
523
/// </summary>
6-
public static class RectangleExtensions
7-
{
8-
/// <summary>
9-
/// Contract a given rectangle (make smaller)
10-
/// </summary>
11-
/// <param name="rectangle">The rectangle to contract</param>
12-
/// <param name="spacing">The amount of space to contract on the sides</param>
13-
/// <returns>A new contacted rectangle</returns>
14-
public static Rectangle Contract(this Rectangle rectangle, Spacing spacing)
15-
=> new Rectangle(
16-
llx: rectangle.LLX + spacing.Left,
17-
lly: rectangle.LLY + spacing.Bottom,
18-
urx: rectangle.URX - spacing.Right,
19-
ury: rectangle.URY - spacing.Top);
24+
/// <param name="rectangle">The rectangle to expand</param>
25+
/// <param name="spacing">The amount of <see cref="Spacing"/> to expand on the sides.</param>
26+
/// <returns>A new expanded <see cref="Rectangle"/>.</returns>
27+
public static Rectangle Expand(this Rectangle rectangle, Spacing spacing)
28+
=> new Rectangle(
29+
llx: rectangle.LLX - spacing.Left,
30+
lly: rectangle.LLY - spacing.Bottom,
31+
urx: rectangle.URX + spacing.Right,
32+
ury: rectangle.URY + spacing.Top);
2033

21-
/// <summary>
22-
/// Expand a given rectangle (make bigger)
23-
/// </summary>
24-
/// <param name="rectangle">The rectangle to expand</param>
25-
/// <param name="spacing">The amount of space to expand on the sides</param>
26-
/// <returns>A new expanded rectangle</returns>
27-
public static Rectangle Expand(this Rectangle rectangle, Spacing spacing)
28-
=> new Rectangle(
29-
llx: rectangle.LLX - spacing.Left,
30-
lly: rectangle.LLY - spacing.Bottom,
31-
urx: rectangle.URX + spacing.Right,
32-
ury: rectangle.URY + spacing.Top);
33-
}
34+
/// <summary>
35+
/// Get the raw values representing this <see cref="Rectangle"/> in a provided unit.
36+
/// </summary>
37+
/// <param name="rectangle">The <see cref="Rectangle"/> to get in raw format.</param>
38+
/// <param name="unit">The unit to get the result in.</param>
39+
/// <returns>A tuple representing the raw values.</returns>
40+
public static (double LLX, double LLY, double URX, double URY) AsRaw(this Rectangle rectangle, Unit unit)
41+
=> (rectangle.LLX.AsRaw(unit), rectangle.LLY.AsRaw(unit), rectangle.URX.AsRaw(unit), rectangle.URY.AsRaw(unit));
3442
}
Original file line numberDiff line numberDiff line change
@@ -1,55 +1,46 @@
1-
namespace Synercoding.Primitives.Extensions
1+
namespace Synercoding.Primitives.Extensions;
2+
3+
/// <summary>
4+
/// Extension class for <seealso cref="Size"/>.
5+
/// </summary>
6+
public static class SizeExtensions
27
{
38
/// <summary>
4-
/// Extension class for <seealso cref="Size"/>
9+
/// Contract a given <see cref="Size"/> (make smaller).
510
/// </summary>
6-
public static class SizeExtensions
7-
{
8-
/// <summary>
9-
/// Contract a given size (make smaller)
10-
/// </summary>
11-
/// <param name="size">The size to contract</param>
12-
/// <param name="spacing">The amount of space to contract on the sides</param>
13-
/// <returns>A new contacted size</returns>
14-
public static Size Contract(this Size size, Spacing spacing)
15-
=> new Size(
16-
width: size.Width - spacing.Left - spacing.Right,
17-
height: size.Height - spacing.Bottom - spacing.Top);
18-
19-
/// <summary>
20-
/// Expand a given size (make bigger)
21-
/// </summary>
22-
/// <param name="size">The size to expand</param>
23-
/// <param name="spacing">The amount of space to expand on the sides</param>
24-
/// <returns>A new expanded size</returns>
25-
public static Size Expand(this Size size, Spacing spacing)
26-
=> new Size(
27-
width: size.Width + spacing.Left + spacing.Right,
28-
height: size.Height + spacing.Bottom + spacing.Top);
11+
/// <param name="size">The <see cref="Size"/> to contract.</param>
12+
/// <param name="spacing">The amount of <see cref="Spacing"/> to contract on the sides.</param>
13+
/// <returns>A new contacted <see cref="Size"/>.</returns>
14+
public static Size Contract(this Size size, Spacing spacing)
15+
=> new Size(
16+
width: size.Width - spacing.Left - spacing.Right,
17+
height: size.Height - spacing.Bottom - spacing.Top);
2918

30-
/// <summary>
31-
/// Get a <see cref="Rectangle"/> with an origin of 0,0 and Width and Height based upon <paramref name="size"/>
32-
/// </summary>
33-
/// <param name="size">The size to base the <see cref="Rectangle"/> on</param>
34-
/// <returns>A new <see cref="Rectangle"/></returns>
35-
public static Rectangle AsRectangle(this Size size)
36-
=> new Rectangle(new Value(0, size.Width.Unit), new Value(0, size.Height.Unit), size.Width, size.Height);
19+
/// <summary>
20+
/// Expand a given <see cref="Size"/> (make bigger).
21+
/// </summary>
22+
/// <param name="size">The <see cref="Size"/> to expand.</param>
23+
/// <param name="spacing">The amount of <see cref="Spacing"/> to expand on the sides.</param>
24+
/// <returns>A new expanded <see cref="Size"/>.</returns>
25+
public static Size Expand(this Size size, Spacing spacing)
26+
=> new Size(
27+
width: size.Width + spacing.Left + spacing.Right,
28+
height: size.Height + spacing.Bottom + spacing.Top);
3729

38-
/// <summary>
39-
/// Get a <see cref="Size"/> where the Width and Height are switched
40-
/// </summary>
41-
/// <param name="size">The size to base the new size on</param>
42-
/// <returns>A new size with width and height switched</returns>
43-
public static Size Rotate(this Size size)
44-
=> new Size(size.Height, size.Width);
30+
/// <summary>
31+
/// Get a <see cref="Rectangle"/> with an <see cref="Rectangle.Location"/> of 0,0 and <see cref="Rectangle.Width"/> and <see cref="Rectangle.Height"/> based upon <paramref name="size"/>.
32+
/// </summary>
33+
/// <param name="size">The <see cref="Size"/> to base the <see cref="Rectangle"/> on.</param>
34+
/// <returns>A new <see cref="Rectangle"/>.</returns>
35+
public static Rectangle AsRectangle(this Size size)
36+
=> new Rectangle(new Value(0, size.Width.Unit), new Value(0, size.Height.Unit), size.Width, size.Height);
4537

46-
/// <summary>
47-
/// Get the raw values representing this Size in a provided unit
48-
/// </summary>
49-
/// <param name="size">The size to get in raw format</param>
50-
/// <param name="unit">The unit to get the result in.</param>
51-
/// <returns>A tuple representing the raw values.</returns>
52-
public static (double Width, double Height) AsRaw(this Size size, Unit unit)
53-
=> (size.Width.AsRaw(unit), size.Height.AsRaw(unit));
54-
}
38+
/// <summary>
39+
/// Get the raw values representing this <see cref="Size"/> in a provided <see cref="Unit"/>.
40+
/// </summary>
41+
/// <param name="size">The <see cref="Size"/> to get in raw format.</param>
42+
/// <param name="unit">The <see cref="Unit"/> to get the result in.</param>
43+
/// <returns>A tuple representing the raw values.</returns>
44+
public static (double Width, double Height) AsRaw(this Size size, Unit unit)
45+
=> (size.Width.AsRaw(unit), size.Height.AsRaw(unit));
5546
}
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,31 @@
11
using System;
22

3-
namespace Synercoding.Primitives.Extensions
3+
namespace Synercoding.Primitives.Extensions;
4+
5+
/// <summary>
6+
/// Extensions for <see cref="UnitDesignation"/>.
7+
/// </summary>
8+
public static class UnitDesignationExtensions
49
{
10+
internal const string CM = "cm";
11+
internal const string IN = "in";
12+
internal const string MM = "mm";
13+
internal const string PX = "px";
14+
internal const string PTS = "pts";
15+
516
/// <summary>
6-
/// Extensions for <see cref="UnitDesignation"/>
17+
/// Get the shortform notation for a <see cref="UnitDesignation"/>.
718
/// </summary>
8-
public static class UnitDesignationExtensions
9-
{
10-
/// <summary>
11-
/// Get the shortform notation for a <see cref="UnitDesignation"/>
12-
/// </summary>
13-
/// <param name="designation">The designation to get the shortform for</param>
14-
/// <returns>The shortform notation for a <see cref="UnitDesignation"/></returns>
15-
public static string Shortform(this UnitDesignation designation)
16-
=> designation switch
17-
{
18-
UnitDesignation.Centimeters => "cm",
19-
UnitDesignation.Inches => "in",
20-
UnitDesignation.Millimeters => "mm",
21-
UnitDesignation.Pixels => "px",
22-
UnitDesignation.Points => "pts",
23-
UnitDesignation x => throw new NotImplementedException($"{x} has no shortform.")
24-
};
25-
}
19+
/// <param name="designation">The designation to get the shortform for.</param>
20+
/// <returns>The shortform notation for a <see cref="UnitDesignation"/>.</returns>
21+
public static string Shortform(this UnitDesignation designation)
22+
=> designation switch
23+
{
24+
UnitDesignation.Centimeters => CM,
25+
UnitDesignation.Inches => IN,
26+
UnitDesignation.Millimeters => MM,
27+
UnitDesignation.Pixels => PX,
28+
UnitDesignation.Points => PTS,
29+
UnitDesignation x => throw new NotImplementedException($"{x} has no shortform.")
30+
};
2631
}

0 commit comments

Comments
 (0)