/// <summary> /// Throws an <see cref="NotFoundException" /> if <paramref name="input" /> with <paramref name="key" /> is not found. /// </summary> /// <typeparam name="T"></typeparam> /// <typeparam name="TKey"></typeparam> /// <param name="guardClause"></param> /// <param name="key"></param> /// <param name="input"></param> /// <param name="parameterName"></param> /// <returns><paramref name="input" /> if the value is not null.</returns> /// <exception cref="NotFoundException"></exception> public static T NotFound <TKey, T>([JetBrainsNotNull] this IGuardClause guardClause, [NotNull, JetBrainsNotNull][ValidatedNotNull] TKey key, [NotNull, JetBrainsNotNull][ValidatedNotNull] T input, [JetBrainsNotNull] string parameterName) where TKey : struct { guardClause.Null(key, nameof(key)); if (input is null) { // TODO: Can we safely consider that ToString() won't return null for struct? throw new NotFoundException(key.ToString() !, parameterName); } return(input); }
public static T NotFound <TKey, T>([JetBrainsNotNull] this IGuardClause guardClause, [NotNull, JetBrainsNotNull][ValidatedNotNull] TKey key, [NotNull, JetBrainsNotNull][ValidatedNotNull][JetBrainsNoEnumeration] T input, [JetBrainsNotNull][JetBrainsInvokerParameterName][CallerArgumentExpression("input")] string?parameterName = null) where TKey : struct #endif { guardClause.Null(key, nameof(key)); if (input is null) { // TODO: Can we safely consider that ToString() won't return null for struct? throw new NotFoundException(key.ToString() !, parameterName !); } return(input); }
public static void NullInvalid <T>(this IGuardClause guardClause, T input, string message) where T : class { guardClause.Null(input, message, ExceptionEventTypes.InvalidParameters); }
public static void NullNotFound <T>(this IGuardClause guardClause, T input, string message) where T : class { guardClause.Null(input, message, ExceptionEventTypes.NotFound); }
public static void NullOrEmpty <T>(this IGuardClause guardClause, IReadOnlyCollection <T> collection, string parameterName) { guardClause.Null(collection, parameterName); guardClause.Empty(collection, parameterName); }