Data Type Declaration
As you have seen, defining the Data Type of an attribute is pretty straight forward.
Simply use the following syntax:
"AttributeName": "[data type]([constraints])"
where [constraints] is optional.
An example:
"GivenName": "String"
Supported Data Types
The following Data Types are supported:
| Dash data type | .NET | SqlServer |
|---|---|---|
string |
String | varchar |
unicode |
String | nvarchar |
int |
Int | int |
bool |
Bool | bit |
datetime |
DateTime | datetime |
guid |
Guid | uniqueidentifier |
For your convenience, the target data type (.NET and SqlServer) is also included.
Constraints
Dash supports constraints that lets you express the limitations of your Attribute.
Optional/Nullable
In Dash, all attributes are required or Non-Nullable.
Similar to C#, use ? to specify that an attribute is optional or Nullable.
Example:
"Nickname": "String?"
Maximum Length
To specify that an attribute has a maximum length, use [length].
Example:
"Nickname": "String[30]"
Default Value
To specify that an attribute has a default value, use (=='default').
Example:
"Nickname": "String(=='Foo')"
In the above example, we specified that the default value for Nickname is Foo.
Regular Expression
To use a regular expression as a constraint, use :[regex]
Example:
"Nickname": "String:[a-zA-Z0-9]{5}"
Mixing Constraints
All constraints can be mixed. For instance, you can specify that an attribute is Nullable and has a Maximum Length of 30:
"Nickname": "String?[30]"
You can put the constraints in any order, except for the Regular Expression constraint, which must always be placed as the final constraint.
"Nickname": "String(=='Foo')[30]?:[a-zA-Z0-9]"