Class FormattableStringHelper
Helpers for composite format strings and FormattableString values and expressions.
public static class FormattableStringHelper
- Inheritance
-
objectFormattableStringHelper
Methods
AreEqual(FormattableString, FormattableString, Func<object?, object?, bool>)
Compares two FormattableString values by format and arguments.
public static bool AreEqual(FormattableString value1, FormattableString value2, Func<object?, object?, bool> argumentsEqual)
Parameters
value1FormattableStringvalue2FormattableStringargumentsEqualFunc<object, object, bool>Compares the two GetArguments() arrays (called once, with the whole arrays).
Returns
ComputeHashCode(FormattableString, Func<object?, int>)
Returns hash code of FormattableString value, consistent with AreEqual(FormattableString, FormattableString, Func<object?, object?, bool>).
public static int ComputeHashCode(FormattableString value, Func<object?, int> argumentsHashCode)
Parameters
valueFormattableStringargumentsHashCodeFunc<object, int>Hashes the GetArguments() array (called once, with the whole array).
Returns
CreateArgumentsExpression(object?[])
Returns new object[] { ... } expression for arguments, with every non-null argument as query parameter.
public static NewArrayExpression CreateArgumentsExpression(object?[] arguments)
Parameters
argumentsobject[]
Returns
CreateExpression(FormattableString)
Returns FormattableStringFactory.Create(format, new object[] { ... }) expression for value, with arguments as query parameters.
public static MethodCallExpression CreateExpression(FormattableString value)
Parameters
valueFormattableString
Returns
CreateExpression(string, Expression)
Returns FormattableStringFactory.Create(format, arguments) expression.
public static MethodCallExpression CreateExpression(string format, Expression arguments)
Parameters
formatstringargumentsExpression
Returns
ParseFormatItems(string)
Returns the format items of composite format string format,
or null when format is not a valid composite format.
public static IReadOnlyList<FormattableStringHelper.FormatItem>? ParseFormatItems(string format)
Parameters
formatstring
Returns
PrepareRawSqlArguments(Expression, bool, out string, out IReadOnlyList<Expression>)
Splits raw SQL argument of FromSql / Sql.Expr into the format and argument expressions.
When the format is a valid composite format with format items, an argument none of them references is replaced with null,
unless it can hold a DataParameter (referenced by name or position instead),
is an ISqlExpression, or keepUnreferenced is set. A format that is not a valid composite format keeps every argument.
public static void PrepareRawSqlArguments(Expression formatArg, bool keepUnreferenced, out string format, out IReadOnlyList<Expression> arguments)
Parameters
formatArgExpressionFormattableStringFactory.Create(format, new object[] { ... })expression, or constant FormattableString.keepUnreferencedboolKeep unreferenced arguments, e.g. when the provider binds parameters by position.
formatstringComposite format of raw SQL.
argumentsIReadOnlyList<Expression>Argument expressions.
Exceptions
- LinqToDBException
formatArghas neither of the shapes above.
TrySplit(Expression, out Expression?, out NewArrayExpression?)
Splits FormattableStringFactory.Create(format, new object[] { ... }) expression into its format and argument array.
public static bool TrySplit(Expression expression, out Expression? format, out NewArrayExpression? arguments)
Parameters
expressionExpressionformatExpressionargumentsNewArrayExpression
Returns
Unescape(string, int, int)
Returns a literal segment of composite format string format with {{ and }} unescaped.
public static string Unescape(string format, int start, int length)