feat: specify ConfigureAwait(false) on async calls

This commit is contained in:
Kyle Ratti 2024-05-03 18:17:44 -04:00
parent 04f94c2441
commit 190db94602
No known key found for this signature in database
GPG Key ID: 4D429B6287C68DD9
2 changed files with 56 additions and 28 deletions

View File

@ -0,0 +1,2 @@
<wpf:ResourceDictionary xml:space="preserve" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:s="clr-namespace:System;assembly=mscorlib" xmlns:ss="urn:shemas-jetbrains-com:settings-storage-xaml" xmlns:wpf="http://schemas.microsoft.com/winfx/2006/xaml/presentation">
<s:String x:Key="/Default/CodeInspection/Daemon/ConfigureAwaitAnalysisMode/@EntryValue">Library</s:String></wpf:ResourceDictionary>

View File

@ -7,48 +7,74 @@ namespace FruityFoundation.Base.Structures;
public static class DbDataReaderMaybeExtensions public static class DbDataReaderMaybeExtensions
{ {
public static async Task<Maybe<bool>> TryGetBooleanAsync(this DbDataReader reader, int ord, CancellationToken cancellationToken = default) => public static async Task<Maybe<bool>> TryGetBooleanAsync(this DbDataReader reader, int ord,
await TryGetAsync(reader, ord, reader.GetBoolean, cancellationToken); CancellationToken cancellationToken = default) =>
await TryGetAsync(reader, ord, reader.GetBoolean, cancellationToken).ConfigureAwait(continueOnCapturedContext: false);
public static async Task<Maybe<byte>> TryGetByteAsync(this DbDataReader reader, int ord, CancellationToken cancellationToken = default) => public static async Task<Maybe<byte>> TryGetByteAsync(this DbDataReader reader, int ord,
await TryGetAsync(reader, ord, reader.GetByte, cancellationToken); CancellationToken cancellationToken = default) =>
await TryGetAsync(reader, ord, reader.GetByte, cancellationToken)
.ConfigureAwait(continueOnCapturedContext: false);
public static async Task<Maybe<long>> TryGetBytesAsync(this DbDataReader reader, int ord, long fieldOffset, byte[]? buffer, int bufferOffset, int length, CancellationToken cancellationToken = default) => public static async Task<Maybe<long>> TryGetBytesAsync(this DbDataReader reader, int ord, long fieldOffset,
await TryGetAsync(reader, ord, _ => reader.GetBytes(ord, fieldOffset, buffer, bufferOffset, length), cancellationToken); byte[]? buffer, int bufferOffset, int length, CancellationToken cancellationToken = default) =>
await TryGetAsync(reader, ord, _ => reader.GetBytes(ord, fieldOffset, buffer, bufferOffset, length),
cancellationToken).ConfigureAwait(continueOnCapturedContext: false);
public static async Task<Maybe<char>> TryGetCharAsync(this DbDataReader reader, int ord, CancellationToken cancellationToken = default) => public static async Task<Maybe<char>> TryGetCharAsync(this DbDataReader reader, int ord,
await TryGetAsync(reader, ord, reader.GetChar, cancellationToken); CancellationToken cancellationToken = default) =>
await TryGetAsync(reader, ord, reader.GetChar, cancellationToken)
.ConfigureAwait(continueOnCapturedContext: false);
public static async Task<Maybe<long>> TryGetCharsAsync(this DbDataReader reader, int ord, long fieldOffset, char[]? buffer, int bufferOffset, int length, CancellationToken cancellationToken = default) => public static async Task<Maybe<long>> TryGetCharsAsync(this DbDataReader reader, int ord, long fieldOffset,
await TryGetAsync(reader, ord, _ => reader.GetChars(ord, fieldOffset, buffer, bufferOffset, length), cancellationToken); char[]? buffer, int bufferOffset, int length, CancellationToken cancellationToken = default) =>
await TryGetAsync(reader, ord, _ => reader.GetChars(ord, fieldOffset, buffer, bufferOffset, length),
cancellationToken).ConfigureAwait(continueOnCapturedContext: false);
public static async Task<Maybe<DateTime>> TryGetDateTimeAsync(this DbDataReader reader, int ord, CancellationToken cancellationToken = default) => public static async Task<Maybe<DateTime>> TryGetDateTimeAsync(this DbDataReader reader, int ord,
await TryGetAsync(reader, ord, reader.GetDateTime, cancellationToken); CancellationToken cancellationToken = default) =>
await TryGetAsync(reader, ord, reader.GetDateTime, cancellationToken)
.ConfigureAwait(continueOnCapturedContext: false);
public static async Task<Maybe<decimal>> TryGetDecimalAsync(this DbDataReader reader, int ord, CancellationToken cancellationToken = default) => public static async Task<Maybe<decimal>> TryGetDecimalAsync(this DbDataReader reader, int ord,
await TryGetAsync(reader, ord, reader.GetDecimal, cancellationToken); CancellationToken cancellationToken = default) =>
await TryGetAsync(reader, ord, reader.GetDecimal, cancellationToken)
.ConfigureAwait(continueOnCapturedContext: false);
public static async Task<Maybe<float>> TryGetFloatAsync(this DbDataReader reader, int ord, CancellationToken cancellationToken = default) => public static async Task<Maybe<float>> TryGetFloatAsync(this DbDataReader reader, int ord,
await TryGetAsync(reader, ord, reader.GetFloat, cancellationToken); CancellationToken cancellationToken = default) =>
await TryGetAsync(reader, ord, reader.GetFloat, cancellationToken)
.ConfigureAwait(continueOnCapturedContext: false);
public static async Task<Maybe<Guid>> TryGetGuidAsync(this DbDataReader reader, int ord, CancellationToken cancellationToken = default) => public static async Task<Maybe<Guid>> TryGetGuidAsync(this DbDataReader reader, int ord,
await TryGetAsync(reader, ord, reader.GetGuid, cancellationToken); CancellationToken cancellationToken = default) =>
await TryGetAsync(reader, ord, reader.GetGuid, cancellationToken)
.ConfigureAwait(continueOnCapturedContext: false);
public static async Task<Maybe<short>> TryGetInt16Async(this DbDataReader reader, int ord, CancellationToken cancellationToken = default) => public static async Task<Maybe<short>> TryGetInt16Async(this DbDataReader reader, int ord,
await TryGetAsync(reader, ord, reader.GetInt16, cancellationToken); CancellationToken cancellationToken = default) =>
await TryGetAsync(reader, ord, reader.GetInt16, cancellationToken)
.ConfigureAwait(continueOnCapturedContext: false);
public static async Task<Maybe<int>> TryGetInt32Async(this DbDataReader reader, int ord, CancellationToken cancellationToken = default) => public static async Task<Maybe<int>> TryGetInt32Async(this DbDataReader reader, int ord,
await TryGetAsync(reader, ord, reader.GetInt32, cancellationToken); CancellationToken cancellationToken = default) =>
await TryGetAsync(reader, ord, reader.GetInt32, cancellationToken)
.ConfigureAwait(continueOnCapturedContext: false);
public static async Task<Maybe<long>> TryGetInt64Async(this DbDataReader reader, int ord, CancellationToken cancellationToken = default) => public static async Task<Maybe<long>> TryGetInt64Async(this DbDataReader reader, int ord,
await TryGetAsync(reader, ord, reader.GetInt64, cancellationToken); CancellationToken cancellationToken = default) =>
await TryGetAsync(reader, ord, reader.GetInt64, cancellationToken)
.ConfigureAwait(continueOnCapturedContext: false);
public static async Task<Maybe<string>> TryGetStringAsync(this DbDataReader reader, int ord, CancellationToken cancellationToken = default) => public static async Task<Maybe<string>> TryGetStringAsync(this DbDataReader reader, int ord,
await TryGetAsync(reader, ord, reader.GetString, cancellationToken); CancellationToken cancellationToken = default) =>
await TryGetAsync(reader, ord, reader.GetString, cancellationToken)
.ConfigureAwait(continueOnCapturedContext: false);
private static async Task<Maybe<T>> TryGetAsync<T>(DbDataReader reader, int ord, Func<int, T> valueGetter, CancellationToken cancellationToken) private static async Task<Maybe<T>> TryGetAsync<T>(DbDataReader reader, int ord, Func<int, T> valueGetter,
CancellationToken cancellationToken)
{ {
if (await reader.IsDBNullAsync(ord, cancellationToken)) if (await reader.IsDBNullAsync(ord, cancellationToken).ConfigureAwait(continueOnCapturedContext: false))
return Maybe.Empty<T>(); return Maybe.Empty<T>();
var value = valueGetter(ord); var value = valueGetter(ord);