Skip to content

Instantly share code, notes, and snippets.

@WrackedFella
Created June 14, 2022 17:55
Show Gist options
  • Save WrackedFella/16ddc62203120c67abaec3f798b167ed to your computer and use it in GitHub Desktop.
Save WrackedFella/16ddc62203120c67abaec3f798b167ed to your computer and use it in GitHub Desktop.
public static class UsefulExtensionMethods
{
public static TModel FirstOrNew<TModel>(this IEnumerable<TModel> queryable) where TModel : new()
=> queryable.FirstOrDefault() ?? new TModel();
public static async Task<TModel> FirstOrNewAsync<TModel>(this IQueryable<TModel> queryable) where TModel : new()
=> (await queryable.FirstOrDefaultAsync()) ?? new TModel();
public static bool IsActuallTheSameAs(this string s1, string s2, StringComparison stringComparison = StringComparison.InvariantCultureIgnoreCase)
=> string.Equals(s1, s2, stringComparison);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment