Skip to content

Commit

Permalink
task: made NumericInfo`1 into an abstract record and implemented a co…
Browse files Browse the repository at this point in the history
…ncrete sealed subclass for each of the integer Primitively info types. Just like the new Double and Single info record types.
  • Loading branch information
dtanglr committed Apr 9, 2024
1 parent 766f742 commit f437dc9
Show file tree
Hide file tree
Showing 19 changed files with 208 additions and 61 deletions.
2 changes: 1 addition & 1 deletion src/Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@

<PropertyGroup Condition="'$(Configuration)' == 'Debug'">
<PackageOutputPath>$(MSBuildThisFileDirectory)..\artifacts</PackageOutputPath>
<version>1.5.0-alpha.25</version>
<version>1.5.0-alpha.27</version>
</PropertyGroup>

<ItemGroup>
Expand Down
17 changes: 17 additions & 0 deletions src/Primitively.Abstractions/ByteInfo.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
namespace Primitively;

/// <summary>
/// This class represents metadata properties common to all source generated Primitively numeric types.
/// </summary>
/// <param name="Type">The .NET type of the Primitively type.</param>
/// <param name="Example">An optional example of the integer.</param>
/// <param name="CreateFrom">A function that creates an instance of the Primitively type from a string.</param>
/// <param name="Minimum">The minimum value that can be set on the source generated Primitively type.</param>
/// <param name="Maximum">The maximum value that can be set on the source generated Primitively type.</param>
public sealed record ByteInfo(
Type Type,
string? Example,
Func<string?, IPrimitive> CreateFrom,
byte Minimum,
byte Maximum)
: NumericInfo<byte>(DataType.Byte, Type, Example, CreateFrom, Minimum, Maximum);
22 changes: 11 additions & 11 deletions src/Primitively.Abstractions/DataType.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,11 @@ public enum DataType
/// </summary>
DateOnly,

/// <summary>
/// Represents an <see cref="IDouble"/> type that encapsulates a <see cref="double"/> value.
/// </summary>
Double,

/// <summary>
/// Represents an <see cref="IGuid"/> type that encapsulates a <see cref="System.Guid"/> value.
/// </summary>
Expand All @@ -40,6 +45,11 @@ public enum DataType
/// </summary>
Short,

/// <summary>
/// Represents an <see cref="ISingle"/> type that encapsulates a <see cref="float"/> value.
/// </summary>
Single,

/// <summary>
/// Represents an <see cref="IString"/> type that encapsulates a <see cref="string"/> value.
/// </summary>
Expand All @@ -58,15 +68,5 @@ public enum DataType
/// <summary>
/// Represents an <see cref="IUShort"/> type that encapsulates a <see cref="ushort"/> value.
/// </summary>
UShort,

/// <summary>
/// Represents an <see cref="ISingle"/> type that encapsulates a <see cref="float"/> value.
/// </summary>
Single,

/// <summary>
/// Represents an <see cref="IDouble"/> type that encapsulates a <see cref="double"/> value.
/// </summary>
Double
UShort
}
10 changes: 7 additions & 3 deletions src/Primitively.Abstractions/DateOnlyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,14 @@
/// This class contains metadata about a Primitively <see cref="IDateOnly"/> type.
/// </summary>
/// <param name="Type">The .NET type of the Primitively type.</param>
/// <param name="ValueType">The .NET type of the encapsulated value.</param>
/// <param name="Example">An optional example of the date.</param>
/// <param name="CreateFrom">A function that creates an instance of the Primitively type from a string.</param>
/// <param name="Format">The format of the date.</param>
/// <param name="Length">The length of the date.</param>
public record DateOnlyInfo(Type Type, Type ValueType, string? Example, Func<string?, IPrimitive> CreateFrom, string Format, int Length)
: PrimitiveInfo(DataType.DateOnly, Type, ValueType, Example, CreateFrom);
public sealed record DateOnlyInfo(
Type Type,
string? Example,
Func<string?, IPrimitive> CreateFrom,
string Format,
int Length)
: PrimitiveInfo(DataType.DateOnly, Type, typeof(DateTime), Example, CreateFrom);
8 changes: 2 additions & 6 deletions src/Primitively.Abstractions/DoubleInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,24 +3,20 @@
/// <summary>
/// This class represents metadata properties common to all source generated Primitively numeric types.
/// </summary>
/// <param name="DataType">The <see cref="DataType"/> enum representation of the Primitively type.</param>
/// <param name="Type">The .NET type of the Primitively type.</param>
/// <param name="ValueType">The .NET type of the encapsulated value.</param>
/// <param name="Example">An optional example of the integer.</param>
/// <param name="CreateFrom">A function that creates an instance of the Primitively type from a string.</param>
/// <param name="Minimum">The minimum value that can be set on the source generated Primitively type.</param>
/// <param name="Maximum">The maximum value that can be set on the source generated Primitively type.</param>
/// <param name="Digits">The number of fractional digits in the value on the source generated Primitively type</param>
/// <param name="Mode">The rounding specification for how to round value of the source generated Primitively type
/// if it is midway between two other numbers.</param>
public record DoubleInfo(
DataType DataType,
public sealed record DoubleInfo(
Type Type,
Type ValueType,
string? Example,
Func<string?, IPrimitive> CreateFrom,
double Minimum,
double Maximum,
int Digits,
MidpointRounding Mode)
: NumericInfo<double>(DataType, Type, ValueType, Example, CreateFrom, Minimum, Maximum);
: NumericInfo<double>(DataType.Double, Type, Example, CreateFrom, Minimum, Maximum);
10 changes: 7 additions & 3 deletions src/Primitively.Abstractions/GuidInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,17 @@
/// This class contains metadata about a Primitively <see cref="IGuid"/> type.
/// </summary>
/// <param name="Type">The .NET type of the Primitively type.</param>
/// <param name="ValueType">The .NET type of the encapsulated value.</param>
/// <param name="Example">An optional example of the GUID in string format.</param>
/// <param name="CreateFrom">A function that creates an instance of the Primitively type from a string.</param>
/// <param name="Specifier">The specifier used to generate the GUID.</param>
/// <param name="Length">The length of the GUID in string format.</param>
public record GuidInfo(Type Type, Type ValueType, string? Example, Func<string?, IPrimitive> CreateFrom, Specifier Specifier, int Length)
: PrimitiveInfo(DataType.Guid, Type, ValueType, Example, CreateFrom)
public sealed record GuidInfo(
Type Type,
string? Example,
Func<string?, IPrimitive> CreateFrom,
Specifier Specifier,
int Length)
: PrimitiveInfo(DataType.Guid, Type, typeof(Guid), Example, CreateFrom)
{
/// <summary>
/// The format of the GUID.
Expand Down
17 changes: 17 additions & 0 deletions src/Primitively.Abstractions/IntInfo.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
namespace Primitively;

/// <summary>
/// This class represents metadata properties common to all source generated Primitively numeric types.
/// </summary>
/// <param name="Type">The .NET type of the Primitively type.</param>
/// <param name="Example">An optional example of the integer.</param>
/// <param name="CreateFrom">A function that creates an instance of the Primitively type from a string.</param>
/// <param name="Minimum">The minimum value that can be set on the source generated Primitively type.</param>
/// <param name="Maximum">The maximum value that can be set on the source generated Primitively type.</param>
public sealed record IntInfo(
Type Type,
string? Example,
Func<string?, IPrimitive> CreateFrom,
int Minimum,
int Maximum)
: NumericInfo<int>(DataType.Int, Type, Example, CreateFrom, Minimum, Maximum);
17 changes: 17 additions & 0 deletions src/Primitively.Abstractions/LongInfo.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
namespace Primitively;

/// <summary>
/// This class represents metadata properties common to all source generated Primitively numeric types.
/// </summary>
/// <param name="Type">The .NET type of the Primitively type.</param>
/// <param name="Example">An optional example of the integer.</param>
/// <param name="CreateFrom">A function that creates an instance of the Primitively type from a string.</param>
/// <param name="Minimum">The minimum value that can be set on the source generated Primitively type.</param>
/// <param name="Maximum">The maximum value that can be set on the source generated Primitively type.</param>
public sealed record LongInfo(
Type Type,
string? Example,
Func<string?, IPrimitive> CreateFrom,
long Minimum,
long Maximum)
: NumericInfo<long>(DataType.Long, Type, Example, CreateFrom, Minimum, Maximum);
7 changes: 6 additions & 1 deletion src/Primitively.Abstractions/NumericInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,10 @@
/// <param name="ValueType">The .NET type of the encapsulated value.</param>
/// <param name="Example">An optional example of the integer.</param>
/// <param name="CreateFrom">A function that creates an instance of the Primitively type from a string.</param>
public abstract record NumericInfo(DataType DataType, Type Type, Type ValueType, string? Example, Func<string?, IPrimitive> CreateFrom)
public abstract record NumericInfo(
DataType DataType,
Type Type,
Type ValueType,
string? Example,
Func<string?, IPrimitive> CreateFrom)
: PrimitiveInfo(DataType, Type, ValueType, Example, CreateFrom);
6 changes: 2 additions & 4 deletions src/Primitively.Abstractions/NumericInfo`1.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,15 @@
/// </summary>
/// <param name="DataType">The <see cref="DataType"/> enum representation of the Primitively type.</param>
/// <param name="Type">The .NET type of the Primitively type.</param>
/// <param name="ValueType">The .NET type of the encapsulated value.</param>
/// <param name="Example">An optional example of the integer.</param>
/// <param name="CreateFrom">A function that creates an instance of the Primitively type from a string.</param>
/// <param name="Minimum">The minimum value that can be set on the source generated Primitively type.</param>
/// <param name="Maximum">The maximum value that can be set on the source generated Primitively type.</param>
public record NumericInfo<T>(
public abstract record NumericInfo<T>(
DataType DataType,
Type Type,
Type ValueType,
string? Example,
Func<string?, IPrimitive> CreateFrom,
T Minimum,
T Maximum)
: NumericInfo(DataType, Type, ValueType, Example, CreateFrom);
: NumericInfo(DataType, Type, typeof(T), Example, CreateFrom);
17 changes: 17 additions & 0 deletions src/Primitively.Abstractions/SByteInfo.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
namespace Primitively;

/// <summary>
/// This class represents metadata properties common to all source generated Primitively numeric types.
/// </summary>
/// <param name="Type">The .NET type of the Primitively type.</param>
/// <param name="Example">An optional example of the integer.</param>
/// <param name="CreateFrom">A function that creates an instance of the Primitively type from a string.</param>
/// <param name="Minimum">The minimum value that can be set on the source generated Primitively type.</param>
/// <param name="Maximum">The maximum value that can be set on the source generated Primitively type.</param>
public sealed record SByteInfo(
Type Type,
string? Example,
Func<string?, IPrimitive> CreateFrom,
sbyte Minimum,
sbyte Maximum)
: NumericInfo<sbyte>(DataType.SByte, Type, Example, CreateFrom, Minimum, Maximum);
17 changes: 17 additions & 0 deletions src/Primitively.Abstractions/ShortInfo.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
namespace Primitively;

/// <summary>
/// This class represents metadata properties common to all source generated Primitively numeric types.
/// </summary>
/// <param name="Type">The .NET type of the Primitively type.</param>
/// <param name="Example">An optional example of the integer.</param>
/// <param name="CreateFrom">A function that creates an instance of the Primitively type from a string.</param>
/// <param name="Minimum">The minimum value that can be set on the source generated Primitively type.</param>
/// <param name="Maximum">The maximum value that can be set on the source generated Primitively type.</param>
public sealed record ShortInfo(
Type Type,
string? Example,
Func<string?, IPrimitive> CreateFrom,
short Minimum,
short Maximum)
: NumericInfo<short>(DataType.Short, Type, Example, CreateFrom, Minimum, Maximum);
6 changes: 1 addition & 5 deletions src/Primitively.Abstractions/SingleInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,7 @@
/// <summary>
/// This class represents metadata properties common to all source generated Primitively numeric types.
/// </summary>
/// <param name="DataType">The <see cref="DataType"/> enum representation of the Primitively type.</param>
/// <param name="Type">The .NET type of the Primitively type.</param>
/// <param name="ValueType">The .NET type of the encapsulated value.</param>
/// <param name="Example">An optional example of the integer.</param>
/// <param name="CreateFrom">A function that creates an instance of the Primitively type from a string.</param>
/// <param name="Minimum">The minimum value that can be set on the source generated Primitively type.</param>
Expand All @@ -14,13 +12,11 @@
/// <param name="Mode">The rounding specification for how to round value of the source generated Primitively type
/// if it is midway between two other numbers.</param>
public record SingleInfo(
DataType DataType,
Type Type,
Type ValueType,
string? Example,
Func<string?, IPrimitive> CreateFrom,
float Minimum,
float Maximum,
int Digits,
MidpointRounding Mode)
: NumericInfo<float>(DataType, Type, ValueType, Example, CreateFrom, Minimum, Maximum);
: NumericInfo<float>(DataType.Single, Type, Example, CreateFrom, Minimum, Maximum);
12 changes: 9 additions & 3 deletions src/Primitively.Abstractions/StringInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,18 @@
/// This class contains metadata about a Primitively <see cref="IString"/> type.
/// </summary>
/// <param name="Type">The Primitively type.</param>
/// <param name="ValueType">The .NET type of the encapsulated value.</param>
/// <param name="Example">An optional example of the string.</param>
/// <param name="CreateFrom">A function that creates an instance of the Primitively type from a string.</param>
/// <param name="Format">An optional format of the string.</param>
/// <param name="Pattern">An optional regular expression pattern used to validate the encapsulated value.</param>
/// <param name="MinLength">The minimum length of the string representation of the encapsulated primitive value.</param>
/// <param name="MaxLength">The maximum length of the string representation of the encapsulated primitive value.</param>
public record StringInfo(Type Type, Type ValueType, string? Example, Func<string?, IPrimitive> CreateFrom, string? Format, string? Pattern, int MinLength, int MaxLength)
: PrimitiveInfo(DataType.String, Type, ValueType, Example, CreateFrom);
public record StringInfo(
Type Type,
string? Example,
Func<string?, IPrimitive> CreateFrom,
string? Format,
string? Pattern,
int MinLength,
int MaxLength)
: PrimitiveInfo(DataType.String, Type, typeof(string), Example, CreateFrom);
17 changes: 17 additions & 0 deletions src/Primitively.Abstractions/UIntInfo.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
namespace Primitively;

/// <summary>
/// This class represents metadata properties common to all source generated Primitively numeric types.
/// </summary>
/// <param name="Type">The .NET type of the Primitively type.</param>
/// <param name="Example">An optional example of the integer.</param>
/// <param name="CreateFrom">A function that creates an instance of the Primitively type from a string.</param>
/// <param name="Minimum">The minimum value that can be set on the source generated Primitively type.</param>
/// <param name="Maximum">The maximum value that can be set on the source generated Primitively type.</param>
public sealed record UIntInfo(
Type Type,
string? Example,
Func<string?, IPrimitive> CreateFrom,
uint Minimum,
uint Maximum)
: NumericInfo<uint>(DataType.UInt, Type, Example, CreateFrom, Minimum, Maximum);
17 changes: 17 additions & 0 deletions src/Primitively.Abstractions/ULongInfo.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
namespace Primitively;

/// <summary>
/// This class represents metadata properties common to all source generated Primitively numeric types.
/// </summary>
/// <param name="Type">The .NET type of the Primitively type.</param>
/// <param name="Example">An optional example of the integer.</param>
/// <param name="CreateFrom">A function that creates an instance of the Primitively type from a string.</param>
/// <param name="Minimum">The minimum value that can be set on the source generated Primitively type.</param>
/// <param name="Maximum">The maximum value that can be set on the source generated Primitively type.</param>
public sealed record ULongInfo(
Type Type,
string? Example,
Func<string?, IPrimitive> CreateFrom,
ulong Minimum,
ulong Maximum)
: NumericInfo<ulong>(DataType.ULong, Type, Example, CreateFrom, Minimum, Maximum);
17 changes: 17 additions & 0 deletions src/Primitively.Abstractions/UShortInfo.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
namespace Primitively;

/// <summary>
/// This class represents metadata properties common to all source generated Primitively numeric types.
/// </summary>
/// <param name="Type">The .NET type of the Primitively type.</param>
/// <param name="Example">An optional example of the integer.</param>
/// <param name="CreateFrom">A function that creates an instance of the Primitively type from a string.</param>
/// <param name="Minimum">The minimum value that can be set on the source generated Primitively type.</param>
/// <param name="Maximum">The maximum value that can be set on the source generated Primitively type.</param>
public sealed record UShortInfo(
Type Type,
string? Example,
Func<string?, IPrimitive> CreateFrom,
ushort Minimum,
ushort Maximum)
: NumericInfo<ushort>(DataType.UShort, Type, Example, CreateFrom, Minimum, Maximum);
Loading

0 comments on commit f437dc9

Please sign in to comment.