For general rule help see Rule Engine Introduction
The Rule Engine implements the following automatic type conversions. Any type conversion not listed is unimplemented and will result in a null value. Note that most but not all conversions are bi-directional.
Null
Type | Rule |
---|---|
String | null |
Long | 0 |
Binary | null |
Boolean | False |
Guid | Empty |
DateTime | MinValue |
TimeSpan | 0 |
Other | null |
Binary
Type | Rule |
---|---|
Boolean | length > 0 |
DateTime | First 8 bytes used with System.DateTime.FromBinary |
Double | If length == 8, use System.BitConverter.ToDouble, else 0.0D |
Long | Based on length, read first byes as Int64, Int32, Int16, or byte and cast to Int64 |
String | Convert.ToBase64String |
Guid | Parse as Guid (returns null if not 16 bytes) |
Boolean
Type | Rule |
---|---|
Binary | byte[] { 1 } or byte[]{} |
Long | 1L or 0L |
Double | 1.0D or 0.0D |
String | "true" or "false" |
DateTime
Type | Rule |
---|---|
Boolean | Value > DateTime.MinValue |
Binary | BitConverter.GetBytes(value.ToBinary()) |
Long | Value.ToBinary() |
String | Value.ToString() |
TimeSpan
Type | Rule |
---|---|
Boolean | Value != TimeSpan.Zero |
Long | Value.Ticks |
String | Value.ToString() |
Double
Note: floats will first be converted to doubles
Type | Rule |
---|---|
Binary | BitConverter.GetBytes(Value) |
Boolean | Value != 0.0 |
Long | .NET cast |
String | Value.ToString() |
Guid
Type | Rule |
---|---|
Binary | Value.ToByteArray() |
Boolean | Value != Guid.Empty |
String | Value.ToString() |
Long
Note: smaller ints (e.g. Int16) will first be converted to Int64
Type | Rule |
---|---|
Binary | BitConverter.GetBytes(Value) |
Boolean | Value != 0 |
Double | .NET cast |
DateTime | DateTime.FromBinary(Value) |
TimeSpan | new TimeSpan(Value) |
String | Value.ToString() |
String
Note: the conversions from string are typically format dependent. If the value is non-compliant, a null or default value will be returned instead.
Type | Rule |
---|---|
Binary | Convert.FromBase64String(Value) |
Boolean | try bool.Parse then length > 0 |
DateTime | DateTime.Parse or DateTime.MinValue |
TimeSpan | TimeSpan.Parse or TimeSpan.Zero |
Double | Double.Parse or 0.0D |
Guid | Guid.Parse or Guid.Empty |
Long | Long.Parse or 0L |
Other
Other refers to any type that's not one of the basic types above, e.g. ObjectRecord.
Type | Rule |
---|---|
String | Serialize as JSON (indented) |
Boolean | Value != null |
Long | Value != null ? 1 : 0 |
Double | Value != null ? 1.0 : 0.0 |
Explicit Type Conversion
The following type coercion functions may be used to explicitly invoke a cast to the desired type. These functions rely on the standard conversion implementations.
CoerceString(val) – converts to System.String CoerceGuid(val) – Converts to System.Guid CoerceBinary(val) – converts to System.Byte[] CoerceLong(val) – converts to System.Int64 CoerceDouble(val) – converts to System.Double CoerceBool(val) – converts to System.Boolean CoerceTimeSpan(val) – Converts to System.TimeSpan CoerceDateTime(val) – Converts to System.DateTime TypeName(val) – Returns type name of the current value as a string
Comments
0 comments
Please sign in to leave a comment.