Table of Contents

Class FormattableStringHelper

Namespace
LinqToDB.Internal.Common
Assembly
linq2db.dll

Helpers for composite format strings and FormattableString values and expressions.

public static class FormattableStringHelper
Inheritance
object
FormattableStringHelper

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

value1 FormattableString
value2 FormattableString
argumentsEqual Func<object, object, bool>

Compares the two GetArguments() arrays (called once, with the whole arrays).

Returns

bool

ComputeHashCode(FormattableString, Func<object?, int>)

public static int ComputeHashCode(FormattableString value, Func<object?, int> argumentsHashCode)

Parameters

value FormattableString
argumentsHashCode Func<object, int>

Hashes the GetArguments() array (called once, with the whole array).

Returns

int

CreateArgumentsExpression(object?[])

Returns new object[] { ... } expression for arguments, with every non-null argument as query parameter.

public static NewArrayExpression CreateArgumentsExpression(object?[] arguments)

Parameters

arguments object[]

Returns

NewArrayExpression

CreateExpression(FormattableString)

Returns FormattableStringFactory.Create(format, new object[] { ... }) expression for value, with arguments as query parameters.

public static MethodCallExpression CreateExpression(FormattableString value)

Parameters

value FormattableString

Returns

MethodCallExpression

CreateExpression(string, Expression)

Returns FormattableStringFactory.Create(format, arguments) expression.

public static MethodCallExpression CreateExpression(string format, Expression arguments)

Parameters

format string
arguments Expression

Returns

MethodCallExpression

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

format string

Returns

IReadOnlyList<FormattableStringHelper.FormatItem>

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

formatArg Expression

FormattableStringFactory.Create(format, new object[] { ... }) expression, or constant FormattableString.

keepUnreferenced bool

Keep unreferenced arguments, e.g. when the provider binds parameters by position.

format string

Composite format of raw SQL.

arguments IReadOnlyList<Expression>

Argument expressions.

Exceptions

LinqToDBException

formatArg has 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

expression Expression
format Expression
arguments NewArrayExpression

Returns

bool

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)

Parameters

format string
start int
length int

Returns

string