ConvertToDateTimeExpression
Table of Contents
What it is
ConvertToDateTimeExpression returns a DateTime, as a result from conversion from another type, for example from a string to a DateTime.
Before converting properties from one type to another, it may be necessary to check if the conversion is possible, in order to prevent runtime errors. When there is no doubt, the conversion can be done without checking.
- See LINQ for details about LINQ and the AI-Framework.
- Go to the category for all LINQ expressions.
Compare with ConvertToDateTimeExpression
Code example
public StringProperty ExampleString => StringProperty(description: "string example");
public DateTimeProperty ExampleDateTime => DateTimeProperty(description: "dateTime example");
public IMethodCall AssignDateTime()
{
return Method(() => new Body
{
new If(ExampleString.CanConvertToDateTime())
{
ExampleDateTime.Assign(ExampleString.ConvertToDateTime())
}
});
}
Explanation of the example
A StringProperty that contains the value "A", can not be converted to a DateTime.
A StringProperty that contains the value "2020-06-21", can be converted to a DateTime. It results in the DateTime June 21 2020.
In this example, the LINQ expression in line 8 ConvertToDateTime checks if the ExampleString can be converted to the type DateTime.
The actual conversion (ConvertToDateTime) is done in line 10.