Example #1
0
 public static void Operation([DoesNotReturnIf(false)] bool condition, string unformattedMessage, params object?[] args)
 {
     if (!condition)
     {
         throw new InvalidOperationException(PrivateErrorHelpers.Format(unformattedMessage, args));
     }
 }
Example #2
0
 public static void Operation(bool condition, string unformattedMessage, object arg1, object arg2)
 {
     if (!condition)
     {
         throw new InvalidOperationException(PrivateErrorHelpers.Format(unformattedMessage, arg1, arg2));
     }
 }
Example #3
0
 public static void IfNot(bool condition, [Localizable(false)] string message, params object?[] args)
 {
     if (!condition)
     {
         Fail(PrivateErrorHelpers.Format(message, args));
     }
 }
Example #4
0
 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));
     }
 }
Example #5
0
 public static void IfNotPresent <T>(T part)
 {
     if (part is null)
     {
         Type coreType = PrivateErrorHelpers.TrimGenericWrapper(typeof(T), typeof(Lazy <>));
         Fail(Strings.ServiceMissing, coreType.FullName);
     }
 }
Example #6
0
        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);
            }
        }
Example #7
0
        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
            }
        }
Example #8
0
        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);
                }
            }
        }
Example #9
0
 public static Exception FailOperation(string message, params object?[] args)
 {
     throw new InvalidOperationException(PrivateErrorHelpers.Format(message, args));
 }
Example #10
0
 /// <summary>
 /// Helper method that formats string arguments.
 /// </summary>
 private static string Format(string format, params object?[] arguments)
 {
     return(PrivateErrorHelpers.Format(format, arguments));
 }
Example #11
0
 public static void Fail([Localizable(false)] string message, params object?[] args)
 {
     Fail(PrivateErrorHelpers.Format(message, args));
 }