Код: Выделить всё
[DoesNotReturn]
public static void ThrowNull([InvokerParameterName] string argName, string? customErrorText = null, [CallerMemberName] string callerName = "") => throw new ArgumentException(AddMethodName(customErrorText != null ? customErrorText.InsertArgs(argName) : Strings.ArgumentMustNotBeNullArgumentTemplate.InsertArgs(callerName), callerName), customErrorText == null ? argName : null);
Код: Выделить всё
public static T ThrowIfNullOrGet([MaybeNull, NotNullIfNotNull("source")] this T source, string argName, string? customErrorText = null, [CallerMemberName] string callerName = "") where T : class
{
if (source != null)
return source;
Requires.ThrowNull(argName, customErrorText, callerName);
return default; // still necessary to prevent compile error
}
Разве DoesNotReturn не исключает необходимости помещать оператор возврата, поскольку это позволяет избежать только предупреждений?
Подробнее здесь: https://stackoverflow.com/questions/605 ... s-expected
Мобильная версия