public static string Get(FormattableString key)
 {
     return(string.Format(Localize(key.Format), key.GetArguments()));
 }
Esempio n. 2
0
 /// <summary>
 /// Append the given operation.
 /// </summary>
 /// <param name="operation">The operation to append.</param>
 public void AppendOperation(FormattableString operation) =>
 AppendOperation(operation.Format, operation.GetArguments());
 /// <summary>
 ///     <para>
 ///         Executes the given SQL against the database and returns the number of rows affected.
 ///     </para>
 ///     <para>
 ///         Note that this method does not start a transaction. To use this method with
 ///         a transaction, first call <see cref="BeginTransaction" /> or <see cref="M:UseTransaction" />.
 ///     </para>
 ///     <para>
 ///         Note that the current <see cref="ExecutionStrategy" /> is not used by this method
 ///         since the SQL may not be idempotent and does not run in a transaction. An <see cref="ExecutionStrategy" />
 ///         can be used explicitly, making sure to also use a transaction if the SQL is not
 ///         idempotent.
 ///     </para>
 ///     <para>
 ///         As with any API that accepts SQL it is important to parameterize any user input to protect against a SQL injection
 ///         attack. You can include parameter place holders in the SQL query string and then supply parameter values as additional
 ///         arguments. Any parameter values you supply will automatically be converted to a DbParameter:
 ///     </para>
 ///     <code>
 ///         var userSuppliedSearchTerm = ".NET";
 ///         context.Database.ExecuteSqlInterpolatedAsync($"SELECT * FROM [dbo].[SearchBlogs]({userSuppliedSearchTerm})")
 ///     </code>
 /// </summary>
 /// <param name="databaseFacade"> The <see cref="DatabaseFacade" /> for the context. </param>
 /// <param name="sql"> The interpolated string representing a SQL query with parameters. </param>
 /// <param name="cancellationToken"> A <see cref="CancellationToken" /> to observe while waiting for the task to complete. </param>
 /// <returns>
 ///     A task that represents the asynchronous operation. The task result is the number of rows affected.
 /// </returns>
 public static Task <int> ExecuteSqlInterpolatedAsync(
     [NotNull] this DatabaseFacade databaseFacade,
     [NotNull] FormattableString sql,
     CancellationToken cancellationToken = default)
 => ExecuteSqlRawAsync(databaseFacade, sql.Format, sql.GetArguments(), cancellationToken);
 public OperationException(FormattableString message, Exception innerException, OperationContext context)
     : base(message.Format, innerException)
 {
     MessageArguments = message.GetArguments();
     Context          = context;
 }
 /// <summary>
 ///     <para>
 ///         Executes the given SQL against the database and returns the number of rows affected.
 ///     </para>
 ///     <para>
 ///         Note that this method does not start a transaction. To use this method with
 ///         a transaction, first call <see cref="BeginTransaction" /> or <see cref="UseTransaction" />.
 ///     </para>
 ///     <para>
 ///         Note that the current <see cref="ExecutionStrategy" /> is not used by this method
 ///         since the SQL may not be idempotent and does not run in a transaction. An ExecutionStrategy
 ///         can be used explicitly, making sure to also use a transaction if the SQL is not
 ///         idempotent.
 ///     </para>
 ///     <para>
 ///         As with any API that accepts SQL it is important to parameterize any user input to protect against a SQL injection
 ///         attack. You can include parameter place holders in the SQL query string and then supply parameter values as additional
 ///         arguments. Any parameter values you supply will automatically be converted to a DbParameter -
 ///         <code>context.Database.ExecuteInterpolatedSql($"SELECT * FROM [dbo].[SearchBlogs]({userSuppliedSearchTerm})")</code>.
 ///     </para>
 /// </summary>
 /// <param name="databaseFacade"> The <see cref="DatabaseFacade" /> for the context. </param>
 /// <param name="sql"> The interpolated string representing a SQL query with parameters. </param>
 /// <returns> The number of rows affected. </returns>
 public static int ExecuteInterpolatedSql(
     [NotNull] this DatabaseFacade databaseFacade,
     [NotNull] FormattableString sql)
 => ExecuteRawSql(databaseFacade, sql.Format, sql.GetArguments());
 /// <summary>
 /// Parses an interpolated-string SQL statement into a injection-safe statement (with parameters as @p0, @p1, etc) and a dictionary of parameter values.
 /// </summary>
 /// <param name="query"></param>
 public InterpolatedStatementParser(FormattableString query) : this(query.Format, query.GetArguments())
 {
 }
Esempio n. 7
0
 public static IEnumerable <T> ExecuteQueryInterpolated <T>(this DatabaseFacade databaseFacade, FormattableString sql)
 => ExecuteQueryRaw <T>(databaseFacade, sql.Format, sql.GetArguments());
Esempio n. 8
0
 /// <inheritdoc />
 public bool Any(FormattableString whereCondition) => Any(whereCondition, whereCondition.GetArguments());
Esempio n. 9
0
 public static RelationalDataReader ExecuteReaderInterpolated(this DatabaseFacade databaseFacade, FormattableString sql)
 => ExecuteReaderRaw(databaseFacade, sql.Format, sql.GetArguments());
Esempio n. 10
0
 public static Task <RelationalDataReader> ExecuteReaderInterpolatedAsync(this DatabaseFacade databaseFacade, FormattableString sql, CancellationToken cancelToken = default)
 => ExecuteReaderRawAsync(databaseFacade, sql.Format, sql.GetArguments(), cancelToken);
Esempio n. 11
0
 public GameString(FormattableString formattableString)
 {
     Literals  = Regex.Split(formattableString.Format, @"{\d+}");
     Variables = formattableString.GetArguments();
 }
Esempio n. 12
0
 public ColorString Append(FormattableString formatString)
 {
     return(AppendFormat(formatString.Format, formatString.GetArguments()));
 }
Esempio n. 13
0
 public JoinableString(FormattableString formattableString)
 {
     _format    = formattableString.Format;
     _arguments = formattableString.GetArguments();
 }
Esempio n. 14
0
 /// <inheritdoc />
 public IFilteredQuery <T> Where(FormattableString whereCondition)
 => Where(whereCondition, whereCondition.GetArguments());
Esempio n. 15
0
 public static IAsyncEnumerable <T> ExecuteQueryInterpolatedAsync <T>(this DatabaseFacade databaseFacade, FormattableString sql, CancellationToken cancelToken = default)
 => ExecuteQueryRawAsync <T>(databaseFacade, sql.Format, sql.GetArguments(), cancelToken);
Esempio n. 16
0
 /// <inheritdoc />
 public T FirstOrDefault(FormattableString whereCondition)
 => FirstOrDefault(whereCondition, whereCondition.GetArguments());
Esempio n. 17
0
 public static T ExecuteScalarInterpolated <T>(this DatabaseFacade databaseFacade, FormattableString sql)
 => ExecuteScalarRaw <T>(databaseFacade, sql.Format, sql.GetArguments());
Esempio n. 18
0
 /// <inheritdoc/>
 public IQueryBase <T> Sql(FormattableString sql) => Sql(sql, sql.GetArguments());
Esempio n. 19
0
 public static Task <T> ExecuteScalarInterpolatedAsync <T>(this DatabaseFacade databaseFacade, FormattableString sql, CancellationToken cancelToken = default)
 => ExecuteScalarRawAsync <T>(databaseFacade, sql.Format, sql.GetArguments(), cancelToken);
Esempio n. 20
0
 public static int ExecuteSqlCommand(
     [NotNull] this DatabaseFacade databaseFacade,
     [NotNull] FormattableString sql)
 => ExecuteSqlCommand(databaseFacade, sql.Format, sql.GetArguments());
 public virtual FormattableString NormalizeDelimetersInInterpolatedString(FormattableString sql)
 => new TestFormattableString(NormalizeDelimetersInRawString(sql.Format), sql.GetArguments());
Esempio n. 22
0
 public static FormattableString FormatConcat(FormattableString first, FormattableString second)
 {
     object?[] newArguments = first.GetArguments().Concat(second.GetArguments()).ToArray();
     return(FormattableStringFactory.Create(first.Format + second.Format, newArguments));
 }
Esempio n. 23
0
 static void M1(FormattableString s) => Console.WriteLine($"format: {s.Format}, args: {string.Join(", ", s.GetArguments())}");
Esempio n. 24
0
 /// <summary>
 ///     <para>
 ///         Executes the given SQL against the database and returns the number of rows affected.
 ///     </para>
 ///     <para>
 ///         Note that this method does not start a transaction. To use this method with
 ///         a transaction, first call <see cref="BeginTransaction" /> or <see cref="M:UseTransaction" />.
 ///     </para>
 ///     <para>
 ///         Note that the current <see cref="ExecutionStrategy" /> is not used by this method
 ///         since the SQL may not be idempotent and does not run in a transaction. An <see cref="ExecutionStrategy" />
 ///         can be used explicitly, making sure to also use a transaction if the SQL is not
 ///         idempotent.
 ///     </para>
 ///     <para>
 ///         As with any API that accepts SQL it is important to parameterize any user input to protect against a SQL injection
 ///         attack. You can include parameter place holders in the SQL query string and then supply parameter values as additional
 ///         arguments. Any parameter values you supply will automatically be converted to a DbParameter:
 ///     </para>
 ///     <code>
 ///         var userSuppliedSearchTerm = ".NET";
 ///         context.Database.ExecuteSqlInterpolated($"UPDATE Blogs SET Rank = 50 WHERE Name = {userSuppliedSearchTerm})");
 ///     </code>
 /// </summary>
 /// <param name="databaseFacade"> The <see cref="DatabaseFacade" /> for the context. </param>
 /// <param name="sql"> The interpolated string representing a SQL query with parameters. </param>
 /// <returns> The number of rows affected. </returns>
 public static int ExecuteSqlInterpolated(
     this DatabaseFacade databaseFacade,
     FormattableString sql)
 => ExecuteSqlRaw(databaseFacade, sql.Format, sql.GetArguments() !);
Esempio n. 25
0
 public void WriteError(Exception exception, FormattableString message)
 {
     _logger.Error(exception, message.Format, message.GetArguments());
 }