Exemple #1
0
        public static T GetOrThrowIfDefault <T>([NotNull, NotNullIfNotNull("source")] this T source, string argName, string?customErrorText = null) where T : struct
        {
            if (Equals(source, default(T)))
            {
                throw ExceptionsHelper.ArgumentDefault(argName, customErrorText);
            }

            return(source);
        }
Exemple #2
0
        public static TValue GetOrThrowIfDefault <TValue>([NotNull, NotNullIfNotNull("source")] this IDictionary <string, object> source, string argName, string?customErrorText = null) where TValue : struct
        {
            var value = (TValue?)source.GetValueOrDefault(argName);

            if (value is null || Equals(value, default(TValue)))
            {
                throw ExceptionsHelper.ArgumentDefault(argName, customErrorText);
            }

            return((TValue)value);
        }