-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #5 from dtanglr/feature/floating-point-numerics
task: added support for floating-point numeric types
- Loading branch information
Showing
128 changed files
with
2,395 additions
and
324 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
namespace Primitively; | ||
|
||
/// <summary> | ||
/// This attribute should be used on a <c>partial record struct</c> to source generate | ||
/// a Primitively <see cref="IDecimal"/> type that encapsulates a <see cref="decimal"/> value. | ||
/// </summary> | ||
/// <example> | ||
/// These examples show how to use the Decimal attribute to source generate a Primitively <see cref="IDecimal"/> type. | ||
/// <code> | ||
/// [Decimal] | ||
/// public partial record struct Example; | ||
/// </code> | ||
/// <code> | ||
/// [Decimal(Minimum = 1)] | ||
/// public partial record struct Example; | ||
/// </code> | ||
/// <code> | ||
/// [Decimal(Minimum = 1, Maximum = 100)] | ||
/// public partial record struct Example; | ||
/// </code> | ||
/// </example> | ||
/// <remarks> | ||
/// The generated Primitively type will enforce the specified minimum and maximum value constraints. | ||
/// </remarks> | ||
[AttributeUsage(AttributeTargets.Struct, Inherited = false, AllowMultiple = false)] | ||
public sealed class DecimalAttribute : NumericAttribute | ||
{ | ||
/// <summary> | ||
/// Gets or sets the minimum value supported by the source generated Primitively <see cref="IDecimal"/> type. | ||
/// </summary> | ||
/// <value> | ||
/// The default value is 0. An assigned value should not be greater than the <see cref="Maximum"/> value. | ||
/// </value> | ||
public new decimal Minimum { get; set; } | ||
|
||
/// <summary> | ||
/// Gets or sets the maximum value supported by the source generated Primitively <see cref="IDecimal"/> type. | ||
/// </summary> | ||
/// <value> | ||
/// The default value is 255. An assigned value should not be less than the <see cref="Minimum"/> value. | ||
/// </value> | ||
public new decimal Maximum { get; set; } | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
namespace Primitively; | ||
|
||
/// <summary> | ||
/// This attribute should be used on a <c>partial record struct</c> to source generate | ||
/// a Primitively <see cref="IDouble"/> type that encapsulates a <see cref="double"/> value. | ||
/// </summary> | ||
/// <example> | ||
/// These examples show how to use the Double attribute to source generate a Primitively <see cref="IDouble"/> type. | ||
/// <code> | ||
/// [Double] | ||
/// public partial record struct Example; | ||
/// </code> | ||
/// <code> | ||
/// [Double(Minimum = 1)] | ||
/// public partial record struct Example; | ||
/// </code> | ||
/// <code> | ||
/// [Double(Minimum = 1, Maximum = 100)] | ||
/// public partial record struct Example; | ||
/// </code> | ||
/// </example> | ||
/// <remarks> | ||
/// The generated Primitively type will enforce the specified minimum and maximum value constraints. | ||
/// </remarks> | ||
[AttributeUsage(AttributeTargets.Struct, Inherited = false, AllowMultiple = false)] | ||
public sealed class DoubleAttribute : NumericAttribute | ||
{ | ||
/// <summary> | ||
/// Gets or sets the minimum value supported by the source generated Primitively <see cref="IDouble"/> type. | ||
/// </summary> | ||
/// <value> | ||
/// The default value is 0. An assigned value should not be greater than the <see cref="Maximum"/> value. | ||
/// </value> | ||
public new double Minimum { get; set; } | ||
|
||
/// <summary> | ||
/// Gets or sets the maximum value supported by the source generated Primitively <see cref="IDouble"/> type. | ||
/// </summary> | ||
/// <value> | ||
/// The default value is 255. An assigned value should not be less than the <see cref="Minimum"/> value. | ||
/// </value> | ||
public new double Maximum { get; set; } | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
namespace Primitively; | ||
|
||
/// <summary> | ||
/// Defines a contract for a Primitively type that encapsulates a <see cref="decimal"/> value. | ||
/// </summary> | ||
/// <remarks> | ||
/// Implementations of this interface are source generated by Primitively and inherit from both <see cref="IPrimitive{T}"/> and <see cref="INumeric"/> interfaces. | ||
/// </remarks> | ||
public interface IDecimal : IPrimitive<decimal>, INumeric | ||
{ | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
namespace Primitively; | ||
|
||
/// <summary> | ||
/// Defines a contract for a Primitively type that encapsulates a <see cref="double"/> value. | ||
/// </summary> | ||
/// <remarks> | ||
/// Implementations of this interface are source generated by Primitively and inherit from both <see cref="IPrimitive{T}"/> and <see cref="INumeric"/> interfaces. | ||
/// </remarks> | ||
public interface IDouble : IPrimitive<double>, INumeric | ||
{ | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4 changes: 2 additions & 2 deletions
4
src/Primitively.Abstractions/IInteger.cs → src/Primitively.Abstractions/INumeric.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,11 @@ | ||
namespace Primitively; | ||
|
||
/// <summary> | ||
/// Defines a contract for a Primitively type that encapsulates an integer value. | ||
/// Defines a contract for a Primitively type that encapsulates a numeric value. | ||
/// </summary> | ||
/// <remarks> | ||
/// Implementations of this interface are source generated by Primitively and inherit from the <see cref="IPrimitive"/> interface. | ||
/// </remarks> | ||
public interface IInteger : IPrimitive | ||
public interface INumeric : IPrimitive | ||
{ | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
namespace Primitively; | ||
|
||
/// <summary> | ||
/// Defines a contract for a Primitively type that encapsulates a <see cref="float"/> value. | ||
/// </summary> | ||
/// <remarks> | ||
/// Implementations of this interface are source generated by Primitively and inherit from both <see cref="IPrimitive{T}"/> and <see cref="INumeric"/> interfaces. | ||
/// </remarks> | ||
public interface ISingle : IPrimitive<float>, INumeric | ||
{ | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
namespace Primitively; | ||
|
||
/// <summary> | ||
/// This abstract class represents metadata properties common to all source generated Primitively integer 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> | ||
public abstract record NumericInfo(DataType DataType, Type Type, Type ValueType, string? Example, Func<string?, IPrimitive> CreateFrom) | ||
: PrimitiveInfo(DataType, Type, ValueType, Example, CreateFrom); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
namespace Primitively; | ||
|
||
/// <summary> | ||
/// This attribute should be used on a <c>partial record struct</c> to source generate | ||
/// a Primitively <see cref="ISingle"/> type that encapsulates a <see cref="float"/> value. | ||
/// </summary> | ||
/// <example> | ||
/// These examples show how to use the Single attribute to source generate a Primitively <see cref="ISingle"/> type. | ||
/// <code> | ||
/// [Single] | ||
/// public partial record struct Example; | ||
/// </code> | ||
/// <code> | ||
/// [Single(Minimum = 1)] | ||
/// public partial record struct Example; | ||
/// </code> | ||
/// <code> | ||
/// [Single(Minimum = 1, Maximum = 100)] | ||
/// public partial record struct Example; | ||
/// </code> | ||
/// </example> | ||
/// <remarks> | ||
/// The generated Primitively type will enforce the specified minimum and maximum value constraints. | ||
/// </remarks> | ||
[AttributeUsage(AttributeTargets.Struct, Inherited = false, AllowMultiple = false)] | ||
public sealed class SingleAttribute : NumericAttribute | ||
{ | ||
/// <summary> | ||
/// Gets or sets the minimum value supported by the source generated Primitively <see cref="ISingle"/> type. | ||
/// </summary> | ||
/// <value> | ||
/// The default value is 0. An assigned value should not be greater than the <see cref="Maximum"/> value. | ||
/// </value> | ||
public new float Minimum { get; set; } | ||
|
||
/// <summary> | ||
/// Gets or sets the maximum value supported by the source generated Primitively <see cref="ISingle"/> type. | ||
/// </summary> | ||
/// <value> | ||
/// The default value is 255. An assigned value should not be less than the <see cref="Minimum"/> value. | ||
/// </value> | ||
public new float Maximum { get; set; } | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.