Class DoubleAttribute
This attribute should be used on a partial record struct
to source generate
a Primitively IDouble type that encapsulates a double value.
Inherited Members
Namespace: Primitively
Assembly: Primitively.Abstractions.dll
Syntax
[AttributeUsage(AttributeTargets.Struct, Inherited = false, AllowMultiple = false)]
public sealed class DoubleAttribute : NumericAttribute
Remarks
The generated Primitively type will enforce the specified minimum and maximum value constraints.
Examples
These examples show how to use the Double attribute to source generate a Primitively IDouble type.
[Double]
public partial record struct Example;
[Double(Minimum = 1.10d)]
public partial record struct Example;
[Double(Minimum = -10.10d, Maximum = 10.10d)]
public partial record struct Example;
[Double(2, Minimum = -10.10d, Maximum = 10.10d)]
public partial record struct Example;
Constructors
DoubleAttribute()
Initializes a new instance of the DoubleAttribute class.
Declaration
public DoubleAttribute()
DoubleAttribute(int)
Initializes a new instance of the DoubleAttribute class with the specified number of fractional digits.
Declaration
public DoubleAttribute(int digits)
Parameters
Type | Name | Description |
---|---|---|
int | digits | The number of fractional digits in the value of the source generated Primitively IDouble type. |
DoubleAttribute(int, MidpointRounding)
Initializes a new instance of the DoubleAttribute class with the specified number of fractional digits and rounding mode.
Declaration
public DoubleAttribute(int digits, MidpointRounding mode)
Parameters
Type | Name | Description |
---|---|---|
int | digits | The number of fractional digits in the value of the source generated Primitively IDouble type. |
MidpointRounding | mode | The rounding specification for how to round value of the source generated Primitively IDouble type if it is midway between two other numbers. |
Properties
Digits
Gets the number of fractional digits in the value of the source generated Primitively IDouble type.
Declaration
public int Digits { get; }
Property Value
Type | Description |
---|---|
int |
Remarks
Valid values are: -1 to 15. Values above 15 will default to: -1. Values below -1 will default to: -1. A value of -1 will result in: no rounding.
Maximum
Gets or sets the maximum value supported by the source generated Primitively IDouble type.
Declaration
public double Maximum { get; set; }
Property Value
Type | Description |
---|---|
double | The default value is double.MaxValue. An assigned value should not be less than the Minimum value. |
Minimum
Gets or sets the minimum value supported by the source generated Primitively IDouble type.
Declaration
public double Minimum { get; set; }
Property Value
Type | Description |
---|---|
double | The default value is double.MinValue. An assigned value should not be greater than the Maximum value. |
Mode
Gets the rounding specification for how to round value of the source generated Primitively IDouble type if it is midway between two other numbers.
Declaration
public MidpointRounding Mode { get; }
Property Value
Type | Description |
---|---|
MidpointRounding |
Remarks
If the value of Digits is -1, this property will have no effect.