Data Types
Enforcer provides the following data types for use in ALFA attributes:
Integer
ALFA type name: integer
.Net type: System.Long
Remarks: All integers in Enforcer are 64-bit. In ALFA, integer literal values are specified in base 10. Eg. 15
represents the number fifteen.
Example ALFA attribute declaration
attribute IntegerAttribute
{
type = integer
. . .
}
Double
ALFA type name: double
.Net type: System.Double
Remarks: All floating point numbers in Enforcer are double precision. In ALFA, any literal value with a decimal separator is treated as a double. Eg. 15.2
represents the number fifteen point two.
Example ALFA attribute declaration
attribute DoubleAttribute
{
type = double
. . .
}
Boolean
ALFA type name: boolean
.Net type: System.Boolean
Remarks: Literal values in ALFA are true
and false
Example ALFA attribute declaration
attribute BooleanAttribute
{
type = boolean
. . .
}
String
ALFA type name: string
.Net type: System.String
Remarks: Literal strings in ALFA can be enclosed in either single or double quotes.
Example ALFA attribute declaration
attribute StringAttribute
{
type = string
. . .
}
Date
ALFA type name: date
.Net type: Rsk.Enforcer.PolicyModels.Date
Remarks: Represents a calendar date. Literal values in ALFA are specified with a string in the format yyyy-MM-dd
that can be parsed to a date, followed by the date type specifier. Eg. "2021-01-08":date
is the ALFA literal for January the 8th, 2021.
Example ALFA attribute declaration
attribute DateAttribute
{
type = date
. . .
}
Time
ALFA type name: time
.Net type: Rsk.Enforcer.PolicyModels.Time
Remarks: Represents a time of day. Literal values in ALFA are specified with a string that can be parsed to a time, followed by the time type specifier. Eg. "12:57:00":time
.
Valid formats are HH:mm:ss
and HH:mm:sszzz
. Times are assumed to be local time rather than UTC.
Example ALFA attribute declaration
attribute TimeAttribute
{
type = time
. . .
}
DateTime
ALFA type name: dateTime
.Net type: System.DateTime
Remarks: Represents a point in time with both a calendar date and time of day. Literal values in ALFA are specified with a string that can be parsed to a .Net DateTime
, followed by the ALFA dateTime
type specifier. Eg. "2021-01-08 12:57:00":dateTime
Example ALFA attribute declaration
attribute DateTimeAttribute
{
type = dateTime
. . .
}
Duration
ALFA type name: duration
.Net type: System.TimeSpan
Remarks: A duration represents the difference between two dates, times or dateTimes.
Literal values in ALFA are specified with a string followed by the duration type specifier, Eg. "3:10:59":duration
represents 3 hours, ten minutes and 59 seconds.
The string component has many acceptable formats:
- Any string which can be directly parsed to a .Net
TimeSpan
is acceptable. - Any string duration in ISO-8601 format. Eg.
P12D6H4M
, representing the period of 12 days, 6 hours, 4 minutes.
Example ALFA attribute declaration
attribute IntegerAttribute
{
type = integer
. . .
}
Money
ALFA type name: money
.Net type: System.Decimal
Remarks: Literal values in ALFA are specified the spame as either literal integer or double types, followed by the money type specifier. Character m
can be used as shorthand when specifying literal money values. Eg. 19.99:money
or 20:m
.
The money
type is appropriate when the required degree of precision is determined by the number of digits to the right of the decimal point. Such numbers are commonly used in financial applications, for currency amounts (for example, $1.00), interest rates (for example, 2.625%), and so forth. Even numbers that are precise to only one decimal digit are handled more accurately by the money
type: 0.1, for example, can be exactly represented by money
, while there's no double
that exactly represents 0.1. Because of this difference in numeric types, unexpected rounding errors can occur in arithmetic calculations when you use double
for decimal data.
Example ALFA attribute declaration
attribute MoneyAttribute
{
type = money
. . .
}