public static void Operation([DoesNotReturnIf(false)] bool condition, string unformattedMessage, params object?[] args) { if (!condition) { throw new InvalidOperationException(PrivateErrorHelpers.Format(unformattedMessage, args)); } }
public static void Operation(bool condition, string unformattedMessage, object arg1, object arg2) { if (!condition) { throw new InvalidOperationException(PrivateErrorHelpers.Format(unformattedMessage, arg1, arg2)); } }
public static void IfNot(bool condition, [Localizable(false)] string message, params object?[] args) { if (!condition) { Fail(PrivateErrorHelpers.Format(message, args)); } }
public static void Present <T>([NotNull] T component) { if (component == null) { Type coreType = PrivateErrorHelpers.TrimGenericWrapper(typeof(T), typeof(Lazy <>)); Fail(string.Format(CultureInfo.CurrentCulture, Strings.ServiceMissing, coreType.FullName)); } }
public static void IfNotPresent <T>(T part) { if (part is null) { Type coreType = PrivateErrorHelpers.TrimGenericWrapper(typeof(T), typeof(Lazy <>)); Fail(Strings.ServiceMissing, coreType.FullName); } }
public static void NotDefault <T>(T value, string parameterName) where T : struct { var defaultValue = default(T); if (defaultValue.Equals(value)) { throw new ArgumentException(PrivateErrorHelpers.Format(Strings.Argument_StructIsDefault, parameterName, typeof(T).FullName), parameterName); } }
public static void IfNotPresent <T>(T part) { if (part == null) { Type coreType = PrivateErrorHelpers.TrimGenericWrapper(typeof(T), typeof(Lazy <>)); #if DESKTOP // TODO: we should remove this entire CPS-specific behavior. if (Environment.GetEnvironmentVariable("CPSUnitTest") != "true") { Fail(Strings.ServiceMissing, coreType.FullName); } #endif } }
public static void ValidElements <T>([ValidatedNotNull] IEnumerable <T> values, Predicate <T> predicate, string?parameterName, string unformattedMessage, params object?[] args) { // To whoever is doing random code cleaning: // Consider the performance when changing the code to delegate to NotNull. // In general do not chain call to another function, check first and return as early as possible. if (values is null) { throw new ArgumentNullException(nameof(values)); } if (predicate is null) { throw new ArgumentNullException(nameof(predicate)); } foreach (T value in values) { if (!predicate(value)) { throw new ArgumentException(PrivateErrorHelpers.Format(unformattedMessage, args), parameterName); } } }
public static Exception FailOperation(string message, params object?[] args) { throw new InvalidOperationException(PrivateErrorHelpers.Format(message, args)); }
/// <summary> /// Helper method that formats string arguments. /// </summary> private static string Format(string format, params object?[] arguments) { return(PrivateErrorHelpers.Format(format, arguments)); }
public static void Fail([Localizable(false)] string message, params object?[] args) { Fail(PrivateErrorHelpers.Format(message, args)); }