diff --git a/src/projects/EnsureThat/Annotations/NotNullAttribute.cs b/src/projects/EnsureThat/Annotations/NotNullAttribute.cs new file mode 100644 index 00000000..b0c97340 --- /dev/null +++ b/src/projects/EnsureThat/Annotations/NotNullAttribute.cs @@ -0,0 +1,23 @@ +// This IF should be 'any new targets we add that natively support NotNullAttribute'. Right now, that is only 2_1. +#if !NETSTANDARD2_1 +// ReSharper disable once CheckNamespace +namespace System.Diagnostics.CodeAnalysis +{ + /// + /// This is JUST so we can avoid having #if regions in each usage site. + /// + /// For non-supported frameworks, it may be ignored by CodeAnalysis, but allows the usage + /// sites to avoid all having + /// + /// #if NETSTANDARD2_1 + /// [NotNull] + /// #endif + /// [OtherAttributes] + /// public string SampleMethod() {} + /// + /// + internal sealed class NotNullAttribute : Attribute + { + } +} +#endif diff --git a/src/projects/EnsureThat/Enforcers/AnyArg.cs b/src/projects/EnsureThat/Enforcers/AnyArg.cs index 71eef498..997c134f 100644 --- a/src/projects/EnsureThat/Enforcers/AnyArg.cs +++ b/src/projects/EnsureThat/Enforcers/AnyArg.cs @@ -1,7 +1,9 @@ -using System; +using System; using EnsureThat.Annotations; using JetBrains.Annotations; +using NotNullAttribute = System.Diagnostics.CodeAnalysis.NotNullAttribute; + namespace EnsureThat.Enforcers { public sealed class AnyArg @@ -18,9 +20,9 @@ public sealed class AnyArg /// /// /// If you know you are dealing with e.g. a struct, the overload is more performant. - [NotNull] + [return: NotNull] [ContractAnnotation("value:null => halt")] - public T HasValue([NoEnumeration, ValidatedNotNull] T value, [InvokerParameterName] string paramName = null, OptsFn optsFn = null) + public T HasValue([NoEnumeration, ValidatedNotNull, NotNull] T value, [InvokerParameterName] string paramName = null, OptsFn optsFn = null) { // ReSharper disable once HeapView.BoxingAllocation if (value == null) @@ -29,9 +31,9 @@ public T HasValue([NoEnumeration, ValidatedNotNull] T value, [InvokerParamete return value; } - [NotNull] + [return: NotNull] [ContractAnnotation("value:null => halt")] - public T IsNotNull([NoEnumeration, ValidatedNotNull] T value, [InvokerParameterName] string paramName = null, OptsFn optsFn = null) where T : class + public T IsNotNull([NoEnumeration, ValidatedNotNull, NotNull] T value, [InvokerParameterName] string paramName = null, OptsFn optsFn = null) where T : class { if (value == null) throw Ensure.ExceptionFactory.ArgumentNullException(ExceptionMessages.Common_IsNotNull_Failed, paramName, optsFn); @@ -39,9 +41,9 @@ public T IsNotNull([NoEnumeration, ValidatedNotNull] T value, [InvokerParamet return value; } - [NotNull] + [return: NotNull] [ContractAnnotation("value:null => halt")] - public T? IsNotNull([ValidatedNotNull] T? value, [InvokerParameterName] string paramName = null, OptsFn optsFn = null) where T : struct + public T? IsNotNull([ValidatedNotNull, NotNull] T? value, [InvokerParameterName] string paramName = null, OptsFn optsFn = null) where T : struct { if (value == null) throw Ensure.ExceptionFactory.ArgumentNullException(ExceptionMessages.Common_IsNotNull_Failed, paramName, optsFn); @@ -57,4 +59,4 @@ public T IsNotDefault(T value, [InvokerParameterName] string paramName = null return value; } } -} \ No newline at end of file +} diff --git a/src/projects/EnsureThat/Enforcers/CollectionArg.cs b/src/projects/EnsureThat/Enforcers/CollectionArg.cs index b54fcec2..a76b3bb7 100644 --- a/src/projects/EnsureThat/Enforcers/CollectionArg.cs +++ b/src/projects/EnsureThat/Enforcers/CollectionArg.cs @@ -6,13 +6,15 @@ using EnsureThat.Annotations; using JetBrains.Annotations; +using NotNullAttribute = System.Diagnostics.CodeAnalysis.NotNullAttribute; + namespace EnsureThat.Enforcers { public sealed class CollectionArg { - [NotNull] + [return: NotNull] [ContractAnnotation("value:null => halt")] - public T HasItems([ValidatedNotNull]T value, [InvokerParameterName] string paramName = null, OptsFn optsFn = null) where T : class, ICollection + public T HasItems([ValidatedNotNull, NotNull]T value, [InvokerParameterName] string paramName = null, OptsFn optsFn = null) where T : class, ICollection { Ensure.Any.IsNotNull(value, paramName); @@ -25,9 +27,9 @@ public T HasItems([ValidatedNotNull]T value, [InvokerParameterName] string pa return value; } - [NotNull] + [return: NotNull] [ContractAnnotation("value:null => halt")] - public ICollection HasItems([ValidatedNotNull]ICollection value, [InvokerParameterName] string paramName = null, OptsFn optsFn = null) + public ICollection HasItems([ValidatedNotNull, NotNull]ICollection value, [InvokerParameterName] string paramName = null, OptsFn optsFn = null) { Ensure.Any.IsNotNull(value, paramName); @@ -40,9 +42,9 @@ public ICollection HasItems([ValidatedNotNull]ICollection value, [Invok return value; } - [NotNull] + [return: NotNull] [ContractAnnotation("value:null => halt")] - public IReadOnlyCollection HasItems([ValidatedNotNull]IReadOnlyCollection value, [InvokerParameterName] string paramName = null, OptsFn optsFn = null) + public IReadOnlyCollection HasItems([ValidatedNotNull, NotNull]IReadOnlyCollection value, [InvokerParameterName] string paramName = null, OptsFn optsFn = null) { Ensure.Any.IsNotNull(value, paramName); @@ -55,9 +57,9 @@ public IReadOnlyCollection HasItems([ValidatedNotNull]IReadOnlyCollection< return value; } - [NotNull] + [return: NotNull] [ContractAnnotation("value:null => halt")] - public IReadOnlyList HasItems([ValidatedNotNull]IReadOnlyList value, [InvokerParameterName] string paramName = null, OptsFn optsFn = null) + public IReadOnlyList HasItems([ValidatedNotNull, NotNull]IReadOnlyList value, [InvokerParameterName] string paramName = null, OptsFn optsFn = null) { Ensure.Any.IsNotNull(value, paramName); @@ -70,9 +72,9 @@ public IReadOnlyList HasItems([ValidatedNotNull]IReadOnlyList value, [I return value; } - [NotNull] + [return: NotNull] [ContractAnnotation("value:null => halt")] - public ISet HasItems([ValidatedNotNull]ISet value, [InvokerParameterName] string paramName = null, OptsFn optsFn = null) + public ISet HasItems([ValidatedNotNull, NotNull]ISet value, [InvokerParameterName] string paramName = null, OptsFn optsFn = null) { Ensure.Any.IsNotNull(value, paramName); @@ -85,9 +87,9 @@ public ISet HasItems([ValidatedNotNull]ISet value, [InvokerParameterNam return value; } - [NotNull] + [return: NotNull] [ContractAnnotation("value:null => halt")] - public T[] HasItems([ValidatedNotNull]T[] value, [InvokerParameterName] string paramName = null, OptsFn optsFn = null) + public T[] HasItems([ValidatedNotNull, NotNull]T[] value, [InvokerParameterName] string paramName = null, OptsFn optsFn = null) { Ensure.Any.IsNotNull(value, paramName); @@ -100,9 +102,9 @@ public T[] HasItems([ValidatedNotNull]T[] value, [InvokerParameterName] strin return value; } - [NotNull] + [return: NotNull] [ContractAnnotation("value:null => halt")] - public IList HasItems([ValidatedNotNull] IList value, [InvokerParameterName] string paramName = null, OptsFn optsFn = null) + public IList HasItems([ValidatedNotNull, NotNull] IList value, [InvokerParameterName] string paramName = null, OptsFn optsFn = null) { Ensure.Any.IsNotNull(value, paramName); @@ -115,9 +117,9 @@ public IList HasItems([ValidatedNotNull] IList value, [InvokerParameter return value; } - [NotNull] + [return: NotNull] [ContractAnnotation("value:null => halt")] - public IDictionary HasItems([ValidatedNotNull]IDictionary value, [InvokerParameterName] string paramName = null, OptsFn optsFn = null) + public IDictionary HasItems([ValidatedNotNull, NotNull]IDictionary value, [InvokerParameterName] string paramName = null, OptsFn optsFn = null) { Ensure.Any.IsNotNull(value, paramName); @@ -130,9 +132,9 @@ public IDictionary HasItems([ValidatedNotNull]IDicti return value; } - [NotNull] + [return: NotNull] [ContractAnnotation("value:null => halt")] - public Collection HasItems([ValidatedNotNull] Collection value, [InvokerParameterName] string paramName = null, OptsFn optsFn = null) + public Collection HasItems([ValidatedNotNull, NotNull] Collection value, [InvokerParameterName] string paramName = null, OptsFn optsFn = null) { Ensure.Any.IsNotNull(value, paramName); @@ -145,9 +147,9 @@ public Collection HasItems([ValidatedNotNull] Collection value, [Invoke return value; } - [NotNull] + [return: NotNull] [ContractAnnotation("value:null => halt")] - public List HasItems([ValidatedNotNull] List value, [InvokerParameterName] string paramName = null, OptsFn optsFn = null) + public List HasItems([ValidatedNotNull, NotNull] List value, [InvokerParameterName] string paramName = null, OptsFn optsFn = null) { Ensure.Any.IsNotNull(value, paramName); @@ -160,9 +162,9 @@ public List HasItems([ValidatedNotNull] List value, [InvokerParameterNa return value; } - [NotNull] + [return: NotNull] [ContractAnnotation("value:null => halt")] - public HashSet HasItems([ValidatedNotNull] HashSet value, [InvokerParameterName] string paramName = null, OptsFn optsFn = null) + public HashSet HasItems([ValidatedNotNull, NotNull] HashSet value, [InvokerParameterName] string paramName = null, OptsFn optsFn = null) { Ensure.Any.IsNotNull(value, paramName); @@ -175,9 +177,9 @@ public HashSet HasItems([ValidatedNotNull] HashSet value, [InvokerParam return value; } - [NotNull] + [return: NotNull] [ContractAnnotation("value:null => halt")] - public Dictionary HasItems([ValidatedNotNull]Dictionary value, [InvokerParameterName] string paramName = null, OptsFn optsFn = null) + public Dictionary HasItems([ValidatedNotNull, NotNull]Dictionary value, [InvokerParameterName] string paramName = null, OptsFn optsFn = null) { Ensure.Any.IsNotNull(value, paramName); @@ -190,9 +192,9 @@ public Dictionary HasItems([ValidatedNotNull]Diction return value; } - [NotNull] + [return: NotNull] [ContractAnnotation("value:null => halt")] - public T[] SizeIs([ValidatedNotNull]T[] value, int expected, [InvokerParameterName] string paramName = null, OptsFn optsFn = null) + public T[] SizeIs([ValidatedNotNull, NotNull]T[] value, int expected, [InvokerParameterName] string paramName = null, OptsFn optsFn = null) { Ensure.Any.IsNotNull(value, paramName); @@ -205,9 +207,9 @@ public T[] SizeIs([ValidatedNotNull]T[] value, int expected, [InvokerParamete return value; } - [NotNull] + [return: NotNull] [ContractAnnotation("value:null => halt")] - public T[] SizeIs([ValidatedNotNull]T[] value, long expected, [InvokerParameterName] string paramName = null, OptsFn optsFn = null) + public T[] SizeIs([ValidatedNotNull, NotNull]T[] value, long expected, [InvokerParameterName] string paramName = null, OptsFn optsFn = null) { Ensure.Any.IsNotNull(value, paramName); @@ -224,9 +226,9 @@ public T[] SizeIs([ValidatedNotNull]T[] value, long expected, [InvokerParamet return value; } - [NotNull] + [return: NotNull] [ContractAnnotation("value:null => halt")] - public T SizeIs([ValidatedNotNull]T value, int expected, [InvokerParameterName] string paramName = null, OptsFn optsFn = null) where T : class, ICollection + public T SizeIs([ValidatedNotNull, NotNull]T value, int expected, [InvokerParameterName] string paramName = null, OptsFn optsFn = null) where T : class, ICollection { Ensure.Any.IsNotNull(value, paramName); @@ -239,9 +241,9 @@ public T SizeIs([ValidatedNotNull]T value, int expected, [InvokerParameterNam return value; } - [NotNull] + [return: NotNull] [ContractAnnotation("value:null => halt")] - public T SizeIs([ValidatedNotNull]T value, long expected, [InvokerParameterName] string paramName = null, OptsFn optsFn = null) where T : class, ICollection + public T SizeIs([ValidatedNotNull, NotNull]T value, long expected, [InvokerParameterName] string paramName = null, OptsFn optsFn = null) where T : class, ICollection { Ensure.Any.IsNotNull(value, paramName); @@ -254,9 +256,9 @@ public T SizeIs([ValidatedNotNull]T value, long expected, [InvokerParameterNa return value; } - [NotNull] + [return: NotNull] [ContractAnnotation("value:null => halt")] - public ICollection SizeIs([ValidatedNotNull]ICollection value, int expected, [InvokerParameterName] string paramName = null, OptsFn optsFn = null) + public ICollection SizeIs([ValidatedNotNull, NotNull]ICollection value, int expected, [InvokerParameterName] string paramName = null, OptsFn optsFn = null) { Ensure.Any.IsNotNull(value, paramName); @@ -269,9 +271,9 @@ public ICollection SizeIs([ValidatedNotNull]ICollection value, int expe return value; } - [NotNull] + [return: NotNull] [ContractAnnotation("value:null => halt")] - public ICollection SizeIs([ValidatedNotNull]ICollection value, long expected, [InvokerParameterName] string paramName = null, OptsFn optsFn = null) + public ICollection SizeIs([ValidatedNotNull, NotNull]ICollection value, long expected, [InvokerParameterName] string paramName = null, OptsFn optsFn = null) { Ensure.Any.IsNotNull(value, paramName); @@ -284,9 +286,9 @@ public ICollection SizeIs([ValidatedNotNull]ICollection value, long exp return value; } - [NotNull] + [return: NotNull] [ContractAnnotation("value:null => halt")] - public IList SizeIs([ValidatedNotNull] IList value, int expected, [InvokerParameterName] string paramName = null, OptsFn optsFn = null) + public IList SizeIs([ValidatedNotNull, NotNull] IList value, int expected, [InvokerParameterName] string paramName = null, OptsFn optsFn = null) { Ensure.Any.IsNotNull(value, paramName); @@ -299,9 +301,9 @@ public IList SizeIs([ValidatedNotNull] IList value, int expected, [Invo return value; } - [NotNull] + [return: NotNull] [ContractAnnotation("value:null => halt")] - public IList SizeIs([ValidatedNotNull]IList value, long expected, [InvokerParameterName] string paramName = null, OptsFn optsFn = null) + public IList SizeIs([ValidatedNotNull, NotNull]IList value, long expected, [InvokerParameterName] string paramName = null, OptsFn optsFn = null) { Ensure.Any.IsNotNull(value, paramName); @@ -314,9 +316,9 @@ public IList SizeIs([ValidatedNotNull]IList value, long expected, [Invo return value; } - [NotNull] + [return: NotNull] [ContractAnnotation("value:null => halt")] - public IDictionary SizeIs([ValidatedNotNull]IDictionary value, int expected, [InvokerParameterName] string paramName = null, OptsFn optsFn = null) + public IDictionary SizeIs([ValidatedNotNull, NotNull]IDictionary value, int expected, [InvokerParameterName] string paramName = null, OptsFn optsFn = null) { Ensure.Any.IsNotNull(value, paramName); @@ -329,9 +331,9 @@ public IDictionary SizeIs([ValidatedNotNull]IDiction return value; } - [NotNull] + [return: NotNull] [ContractAnnotation("value:null => halt")] - public IDictionary SizeIs([ValidatedNotNull]IDictionary value, long expected, [InvokerParameterName] string paramName = null, OptsFn optsFn = null) + public IDictionary SizeIs([ValidatedNotNull, NotNull]IDictionary value, long expected, [InvokerParameterName] string paramName = null, OptsFn optsFn = null) { Ensure.Any.IsNotNull(value, paramName); @@ -344,9 +346,9 @@ public IDictionary SizeIs([ValidatedNotNull]IDiction return value; } - [NotNull] + [return: NotNull] [ContractAnnotation("value:null => halt")] - public IDictionary ContainsKey([ValidatedNotNull]IDictionary value, TKey expectedKey, [InvokerParameterName] string paramName = null, OptsFn optsFn = null) + public IDictionary ContainsKey([ValidatedNotNull, NotNull]IDictionary value, TKey expectedKey, [InvokerParameterName] string paramName = null, OptsFn optsFn = null) { Ensure.Any.IsNotNull(value, paramName); @@ -359,9 +361,9 @@ public IDictionary ContainsKey([ValidatedNotNull]IDi return value; } - [NotNull] + [return: NotNull] [ContractAnnotation("value:null => halt")] - public IList HasAny([ValidatedNotNull]IList value, Func predicate, [InvokerParameterName] string paramName = null, OptsFn optsFn = null) + public IList HasAny([ValidatedNotNull, NotNull]IList value, Func predicate, [InvokerParameterName] string paramName = null, OptsFn optsFn = null) { Ensure.Any.IsNotNull(value, paramName); @@ -374,9 +376,9 @@ public IList HasAny([ValidatedNotNull]IList value, Func predic return value; } - [NotNull] + [return: NotNull] [ContractAnnotation("value:null => halt")] - public ICollection HasAny([ValidatedNotNull]ICollection value, Func predicate, [InvokerParameterName] string paramName = null, OptsFn optsFn = null) + public ICollection HasAny([ValidatedNotNull, NotNull]ICollection value, Func predicate, [InvokerParameterName] string paramName = null, OptsFn optsFn = null) { Ensure.Any.IsNotNull(value, paramName); @@ -389,9 +391,9 @@ public ICollection HasAny([ValidatedNotNull]ICollection value, Func halt")] - public T[] HasAny([ValidatedNotNull]T[] value, Func predicate, [InvokerParameterName] string paramName = null, OptsFn optsFn = null) + public T[] HasAny([ValidatedNotNull, NotNull]T[] value, Func predicate, [InvokerParameterName] string paramName = null, OptsFn optsFn = null) { Ensure.Any.IsNotNull(value, paramName); @@ -404,4 +406,4 @@ public T[] HasAny([ValidatedNotNull]T[] value, Func predicate, [Invo return value; } } -} \ No newline at end of file +} diff --git a/src/projects/EnsureThat/Enforcers/EnumerableArg.cs b/src/projects/EnsureThat/Enforcers/EnumerableArg.cs index 7c83be7e..39568634 100644 --- a/src/projects/EnsureThat/Enforcers/EnumerableArg.cs +++ b/src/projects/EnsureThat/Enforcers/EnumerableArg.cs @@ -5,6 +5,8 @@ using EnsureThat.Annotations; using JetBrains.Annotations; +using NotNullAttribute = System.Diagnostics.CodeAnalysis.NotNullAttribute; + namespace EnsureThat.Enforcers { /// @@ -14,7 +16,7 @@ namespace EnsureThat.Enforcers [SuppressMessage("ReSharper", "PossibleMultipleEnumeration")] public sealed class EnumerableArg { - [NotNull] + [return: NotNull] [ContractAnnotation("value:null => halt")] public IEnumerable HasItems([ValidatedNotNull, InstantHandle]IEnumerable value, [InvokerParameterName] string paramName = null, OptsFn optsFn = null) { @@ -29,7 +31,7 @@ public IEnumerable HasItems([ValidatedNotNull, InstantHandle]IEnumerable halt")] public IEnumerable SizeIs([ValidatedNotNull, InstantHandle]IEnumerable value, int expected, [InvokerParameterName] string paramName = null, OptsFn optsFn = null) { @@ -46,7 +48,7 @@ public IEnumerable SizeIs([ValidatedNotNull, InstantHandle]IEnumerable return value; } - [NotNull] + [return: NotNull] [ContractAnnotation("value:null => halt")] public IEnumerable SizeIs([ValidatedNotNull, InstantHandle]IEnumerable value, long expected, [InvokerParameterName] string paramName = null, OptsFn optsFn = null) { @@ -69,7 +71,7 @@ public IEnumerable SizeIs([ValidatedNotNull, InstantHandle]IEnumerable return value; } - [NotNull] + [return: NotNull] [ContractAnnotation("value:null => halt")] public IEnumerable HasAny([ValidatedNotNull, InstantHandle]IEnumerable value, Func predicate, [InvokerParameterName] string paramName = null, OptsFn optsFn = null) { @@ -84,4 +86,4 @@ public IEnumerable HasAny([ValidatedNotNull, InstantHandle]IEnumerable return value; } } -} \ No newline at end of file +} diff --git a/src/projects/EnsureThat/Enforcers/StringArg.cs b/src/projects/EnsureThat/Enforcers/StringArg.cs index 9b2897e3..fb00d891 100644 --- a/src/projects/EnsureThat/Enforcers/StringArg.cs +++ b/src/projects/EnsureThat/Enforcers/StringArg.cs @@ -1,25 +1,27 @@ -using System; +using System; using System.Linq; using System.Text.RegularExpressions; using EnsureThat.Annotations; using JetBrains.Annotations; +using NotNullAttribute = System.Diagnostics.CodeAnalysis.NotNullAttribute; + namespace EnsureThat.Enforcers { public sealed class StringArg { - [NotNull] + [return: NotNull] [ContractAnnotation("value:null => halt")] - public string IsNotNull([ValidatedNotNull]string value, [InvokerParameterName] string paramName = null, OptsFn optsFn = null) + public string IsNotNull([ValidatedNotNull, NotNull]string value, [InvokerParameterName] string paramName = null, OptsFn optsFn = null) { Ensure.Any.IsNotNull(value, paramName, optsFn); return value; } - [NotNull] + [return: NotNull] [ContractAnnotation("value:null => halt")] - public string IsNotNullOrWhiteSpace([ValidatedNotNull]string value, [InvokerParameterName] string paramName = null, OptsFn optsFn = null) + public string IsNotNullOrWhiteSpace([ValidatedNotNull, NotNull]string value, [InvokerParameterName] string paramName = null, OptsFn optsFn = null) { Ensure.Any.IsNotNull(value, paramName, optsFn); @@ -29,8 +31,8 @@ public string IsNotNullOrWhiteSpace([ValidatedNotNull]string value, [InvokerPara return value; } - [NotNull] - public string IsNotNullOrEmpty([ValidatedNotNull]string value, [InvokerParameterName] string paramName = null, OptsFn optsFn = null) + [return: NotNull] + public string IsNotNullOrEmpty([ValidatedNotNull, NotNull]string value, [InvokerParameterName] string paramName = null, OptsFn optsFn = null) { Ensure.Any.IsNotNull(value, paramName, optsFn); @@ -69,9 +71,9 @@ public string IsNotEmpty(string value, [InvokerParameterName] string paramName = return value; } - [NotNull] + [return: NotNull] [ContractAnnotation("value:null => halt")] - public string HasLength([ValidatedNotNull]string value, int expected, [InvokerParameterName] string paramName = null, OptsFn optsFn = null) + public string HasLength([ValidatedNotNull, NotNull]string value, int expected, [InvokerParameterName] string paramName = null, OptsFn optsFn = null) { Ensure.Any.IsNotNull(value, paramName, optsFn); @@ -84,9 +86,9 @@ public string HasLength([ValidatedNotNull]string value, int expected, [InvokerPa return value; } - [NotNull] + [return: NotNull] [ContractAnnotation("value:null => halt")] - public string HasLengthBetween([ValidatedNotNull]string value, int minLength, int maxLength, [InvokerParameterName] string paramName = null, OptsFn optsFn = null) + public string HasLengthBetween([ValidatedNotNull, NotNull]string value, int minLength, int maxLength, [InvokerParameterName] string paramName = null, OptsFn optsFn = null) { Ensure.Any.IsNotNull(value, paramName, optsFn); @@ -107,11 +109,11 @@ public string HasLengthBetween([ValidatedNotNull]string value, int minLength, in return value; } - [NotNull] + [return: NotNull] public string Matches(string value, [RegexPattern] string match, [InvokerParameterName] string paramName = null, OptsFn optsFn = null) => Matches(value, new Regex(match), paramName, optsFn); - [NotNull] + [return: NotNull] public string Matches(string value, Regex match, [InvokerParameterName] string paramName = null, OptsFn optsFn = null) { if (!match.IsMatch(value)) @@ -123,10 +125,10 @@ public string Matches(string value, Regex match, [InvokerParameterName] string p return value; } - [NotNull] + [return: NotNull] [ContractAnnotation("value:null => halt")] [Obsolete("Use 'HasLength' instead. This will be removed in an upcoming version.")] - public string SizeIs([ValidatedNotNull] string value, int expected, [InvokerParameterName] string paramName = null, OptsFn optsFn = null) + public string SizeIs([ValidatedNotNull, NotNull] string value, int expected, [InvokerParameterName] string paramName = null, OptsFn optsFn = null) => HasLength(value, expected, paramName, optsFn); public string Is(string value, string expected, [InvokerParameterName] string paramName = null, OptsFn optsFn = null) @@ -185,9 +187,9 @@ public string IsNotEqualTo(string value, string notExpected, StringComparison co return value; } - [NotNull] + [return: NotNull] [ContractAnnotation("value:null => halt")] - public Guid IsGuid([ValidatedNotNull]string value, [InvokerParameterName] string paramName = null, OptsFn optsFn = null) + public Guid IsGuid([ValidatedNotNull, NotNull]string value, [InvokerParameterName] string paramName = null, OptsFn optsFn = null) { if (!Guid.TryParse(value, out var parsed)) throw Ensure.ExceptionFactory.ArgumentException( @@ -198,9 +200,9 @@ public Guid IsGuid([ValidatedNotNull]string value, [InvokerParameterName] string return parsed; } - [NotNull] + [return: NotNull] [ContractAnnotation("value:null => halt")] - public string StartsWith([ValidatedNotNull]string value, [NotNull] string expectedStartsWith, [InvokerParameterName] string paramName = null, OptsFn optsFn = null) + public string StartsWith([ValidatedNotNull, NotNull]string value, [NotNull] string expectedStartsWith, [InvokerParameterName] string paramName = null, OptsFn optsFn = null) { Ensure.Any.IsNotNull(value, paramName, optsFn); @@ -213,9 +215,9 @@ public string StartsWith([ValidatedNotNull]string value, [NotNull] string expect return value; } - [NotNull] + [return: NotNull] [ContractAnnotation("value:null => halt")] - public string StartsWith([ValidatedNotNull]string value, [NotNull] string expectedStartsWith, StringComparison comparison, [InvokerParameterName] string paramName = null, OptsFn optsFn = null) + public string StartsWith([ValidatedNotNull, NotNull]string value, [NotNull] string expectedStartsWith, StringComparison comparison, [InvokerParameterName] string paramName = null, OptsFn optsFn = null) { Ensure.Any.IsNotNull(value, paramName, optsFn); @@ -277,9 +279,9 @@ public string IsInRange(string value, string min, string max, StringComparison c return value; } - [NotNull] + [return: NotNull] [ContractAnnotation("value:null => halt")] - public string IsAllLettersOrDigits([ValidatedNotNull] string value, [InvokerParameterName] string paramName = null, OptsFn optsFn = null) + public string IsAllLettersOrDigits([ValidatedNotNull, NotNull] string value, [InvokerParameterName] string paramName = null, OptsFn optsFn = null) { Ensure.Any.IsNotNull(value, paramName, optsFn); diff --git a/src/projects/EnsureThat/Enforcers/TypeArg.cs b/src/projects/EnsureThat/Enforcers/TypeArg.cs index 483d9719..fd54aecf 100644 --- a/src/projects/EnsureThat/Enforcers/TypeArg.cs +++ b/src/projects/EnsureThat/Enforcers/TypeArg.cs @@ -3,6 +3,8 @@ using EnsureThat.Annotations; using JetBrains.Annotations; +using NotNullAttribute = System.Diagnostics.CodeAnalysis.NotNullAttribute; + namespace EnsureThat.Enforcers { public sealed class TypeArg @@ -26,89 +28,89 @@ private static class Types internal static readonly Type StringType = typeof(string); } - [NotNull] + [return: NotNull] [ContractAnnotation("param:null => halt")] - public Type IsInt([ValidatedNotNull]Type param, [InvokerParameterName] string paramName = null, OptsFn optsFn = null) + public Type IsInt([ValidatedNotNull, NotNull]Type param, [InvokerParameterName] string paramName = null, OptsFn optsFn = null) => IsOfType(param, Types.IntType, paramName, optsFn); - [NotNull] + [return: NotNull] [ContractAnnotation("param:null => halt")] - public object IsInt([ValidatedNotNull]object param, [InvokerParameterName] string paramName = null, OptsFn optsFn = null) + public object IsInt([ValidatedNotNull, NotNull]object param, [InvokerParameterName] string paramName = null, OptsFn optsFn = null) => IsOfType(param, Types.IntType, paramName, optsFn); - [NotNull] + [return: NotNull] [ContractAnnotation("param:null => halt")] - public Type IsShort([ValidatedNotNull]Type param, [InvokerParameterName] string paramName = null, OptsFn optsFn = null) + public Type IsShort([ValidatedNotNull, NotNull]Type param, [InvokerParameterName] string paramName = null, OptsFn optsFn = null) => IsOfType(param, Types.ShortType, paramName, optsFn); - [NotNull] + [return: NotNull] [ContractAnnotation("param:null => halt")] - public object IsShort([ValidatedNotNull]object param, [InvokerParameterName] string paramName = null, OptsFn optsFn = null) + public object IsShort([ValidatedNotNull, NotNull]object param, [InvokerParameterName] string paramName = null, OptsFn optsFn = null) => IsOfType(param, Types.ShortType, paramName, optsFn); - [NotNull] + [return: NotNull] [ContractAnnotation("param:null => halt")] - public Type IsDecimal([ValidatedNotNull]Type param, [InvokerParameterName] string paramName = null, OptsFn optsFn = null) + public Type IsDecimal([ValidatedNotNull, NotNull]Type param, [InvokerParameterName] string paramName = null, OptsFn optsFn = null) => IsOfType(param, Types.DecimalType, paramName, optsFn); - [NotNull] + [return: NotNull] [ContractAnnotation("param:null => halt")] - public object IsDecimal([ValidatedNotNull]object param, [InvokerParameterName] string paramName = null, OptsFn optsFn = null) + public object IsDecimal([ValidatedNotNull, NotNull]object param, [InvokerParameterName] string paramName = null, OptsFn optsFn = null) => IsOfType(param, Types.DecimalType, paramName, optsFn); - [NotNull] + [return: NotNull] [ContractAnnotation("param:null => halt")] - public Type IsDouble([ValidatedNotNull]Type param, [InvokerParameterName] string paramName = null, OptsFn optsFn = null) + public Type IsDouble([ValidatedNotNull, NotNull]Type param, [InvokerParameterName] string paramName = null, OptsFn optsFn = null) => IsOfType(param, Types.DoubleType, paramName, optsFn); - [NotNull] + [return: NotNull] [ContractAnnotation("param:null => halt")] - public object IsDouble([ValidatedNotNull]object param, [InvokerParameterName] string paramName = null, OptsFn optsFn = null) + public object IsDouble([ValidatedNotNull, NotNull]object param, [InvokerParameterName] string paramName = null, OptsFn optsFn = null) => IsOfType(param, Types.DoubleType, paramName, optsFn); - [NotNull] + [return: NotNull] [ContractAnnotation("param:null => halt")] - public Type IsFloat([ValidatedNotNull]Type param, [InvokerParameterName] string paramName = null, OptsFn optsFn = null) + public Type IsFloat([ValidatedNotNull, NotNull]Type param, [InvokerParameterName] string paramName = null, OptsFn optsFn = null) => IsOfType(param, Types.FloatType, paramName, optsFn); - [NotNull] + [return: NotNull] [ContractAnnotation("param:null => halt")] - public object IsFloat([ValidatedNotNull]object param, [InvokerParameterName] string paramName = null, OptsFn optsFn = null) + public object IsFloat([ValidatedNotNull, NotNull]object param, [InvokerParameterName] string paramName = null, OptsFn optsFn = null) => IsOfType(param, Types.FloatType, paramName, optsFn); - [NotNull] + [return: NotNull] [ContractAnnotation("param:null => halt")] - public Type IsBool([ValidatedNotNull]Type param, [InvokerParameterName] string paramName = null, OptsFn optsFn = null) + public Type IsBool([ValidatedNotNull, NotNull]Type param, [InvokerParameterName] string paramName = null, OptsFn optsFn = null) => IsOfType(param, Types.BoolType, paramName, optsFn); - [NotNull] + [return: NotNull] [ContractAnnotation("param:null => halt")] - public object IsBool([ValidatedNotNull]object param, [InvokerParameterName] string paramName = null, OptsFn optsFn = null) + public object IsBool([ValidatedNotNull, NotNull]object param, [InvokerParameterName] string paramName = null, OptsFn optsFn = null) => IsOfType(param, Types.BoolType, paramName, optsFn); - [NotNull] + [return: NotNull] [ContractAnnotation("param:null => halt")] - public Type IsDateTime([ValidatedNotNull]Type param, [InvokerParameterName] string paramName = null, OptsFn optsFn = null) + public Type IsDateTime([ValidatedNotNull, NotNull]Type param, [InvokerParameterName] string paramName = null, OptsFn optsFn = null) => IsOfType(param, Types.DateTimeType, paramName, optsFn); - [NotNull] + [return: NotNull] [ContractAnnotation("param:null => halt")] - public object IsDateTime([ValidatedNotNull]object param, [InvokerParameterName] string paramName = null, OptsFn optsFn = null) + public object IsDateTime([ValidatedNotNull, NotNull]object param, [InvokerParameterName] string paramName = null, OptsFn optsFn = null) => IsOfType(param, Types.DateTimeType, paramName, optsFn); - [NotNull] + [return: NotNull] [ContractAnnotation("param:null => halt")] - public Type IsString([ValidatedNotNull]Type param, [InvokerParameterName] string paramName = null, OptsFn optsFn = null) + public Type IsString([ValidatedNotNull, NotNull]Type param, [InvokerParameterName] string paramName = null, OptsFn optsFn = null) => IsOfType(param, Types.StringType, paramName, optsFn); - [NotNull] + [return: NotNull] [ContractAnnotation("param:null => halt")] - public object IsString([ValidatedNotNull]object param, [InvokerParameterName] string paramName = null, OptsFn optsFn = null) + public object IsString([ValidatedNotNull, NotNull]object param, [InvokerParameterName] string paramName = null, OptsFn optsFn = null) => IsOfType(param, Types.StringType, paramName, optsFn); - [NotNull] + [return: NotNull] [ContractAnnotation("param:null => halt")] - public T IsOfType([ValidatedNotNull]T param, Type expectedType, [InvokerParameterName] string paramName = null, OptsFn optsFn = null) where T : class + public T IsOfType([ValidatedNotNull, NotNull]T param, Type expectedType, [InvokerParameterName] string paramName = null, OptsFn optsFn = null) where T : class { Ensure.Any.IsNotNull(param, paramName, optsFn); @@ -117,9 +119,9 @@ public T IsOfType([ValidatedNotNull]T param, Type expectedType, [InvokerParam return param; } - [NotNull] + [return: NotNull] [ContractAnnotation("param:null => halt")] - public Type IsOfType([ValidatedNotNull]Type param, Type expectedType, [InvokerParameterName] string paramName = null, OptsFn optsFn = null) + public Type IsOfType([ValidatedNotNull, NotNull]Type param, Type expectedType, [InvokerParameterName] string paramName = null, OptsFn optsFn = null) { Ensure.Any.IsNotNull(param, paramName, optsFn); Ensure.Any.IsNotNull(expectedType, nameof(expectedType)); @@ -133,9 +135,9 @@ public Type IsOfType([ValidatedNotNull]Type param, Type expectedType, [InvokerPa return param; } - [NotNull] + [return: NotNull] [ContractAnnotation("param:null => halt")] - public T IsNotOfType([ValidatedNotNull]T param, Type nonExpectedType, [InvokerParameterName] string paramName = null, OptsFn optsFn = null) where T : class + public T IsNotOfType([ValidatedNotNull, NotNull]T param, Type nonExpectedType, [InvokerParameterName] string paramName = null, OptsFn optsFn = null) where T : class { Ensure.Any.IsNotNull(param, paramName, optsFn); @@ -144,9 +146,9 @@ public T IsNotOfType([ValidatedNotNull]T param, Type nonExpectedType, [Invoke return param; } - [NotNull] + [return: NotNull] [ContractAnnotation("param:null => halt")] - public Type IsNotOfType([ValidatedNotNull]Type param, Type nonExpectedType, [InvokerParameterName] string paramName = null, OptsFn optsFn = null) + public Type IsNotOfType([ValidatedNotNull, NotNull]Type param, Type nonExpectedType, [InvokerParameterName] string paramName = null, OptsFn optsFn = null) { Ensure.Any.IsNotNull(param, paramName, optsFn); Ensure.Any.IsNotNull(nonExpectedType, nameof(nonExpectedType)); @@ -160,9 +162,9 @@ public Type IsNotOfType([ValidatedNotNull]Type param, Type nonExpectedType, [Inv return param; } - [NotNull] + [return: NotNull] [ContractAnnotation("param:null => halt")] - public T IsAssignableToType([ValidatedNotNull]T param, Type expectedType, [InvokerParameterName] string paramName = null, OptsFn optsFn = null) where T : class + public T IsAssignableToType([ValidatedNotNull, NotNull]T param, Type expectedType, [InvokerParameterName] string paramName = null, OptsFn optsFn = null) where T : class { Ensure.Any.IsNotNull(param, paramName, optsFn); @@ -171,9 +173,9 @@ public T IsAssignableToType([ValidatedNotNull]T param, Type expectedType, [In return param; } - [NotNull] + [return: NotNull] [ContractAnnotation("param:null => halt")] - public Type IsAssignableToType([ValidatedNotNull]Type param, Type expectedType, [InvokerParameterName] string paramName = null, OptsFn optsFn = null) + public Type IsAssignableToType([ValidatedNotNull, NotNull]Type param, Type expectedType, [InvokerParameterName] string paramName = null, OptsFn optsFn = null) { Ensure.Any.IsNotNull(param, paramName, optsFn); Ensure.Any.IsNotNull(expectedType, nameof(expectedType)); @@ -192,9 +194,9 @@ public Type IsAssignableToType([ValidatedNotNull]Type param, Type expectedType, return param; } - [NotNull] + [return: NotNull] [ContractAnnotation("param:null => halt")] - public T IsNotAssignableToType([ValidatedNotNull]T param, Type nonExpectedType, [InvokerParameterName] string paramName = null, OptsFn optsFn = null) where T : class + public T IsNotAssignableToType([ValidatedNotNull, NotNull]T param, Type nonExpectedType, [InvokerParameterName] string paramName = null, OptsFn optsFn = null) where T : class { Ensure.Any.IsNotNull(param, paramName, optsFn); @@ -203,9 +205,9 @@ public T IsNotAssignableToType([ValidatedNotNull]T param, Type nonExpectedTyp return param; } - [NotNull] + [return: NotNull] [ContractAnnotation("param:null => halt")] - public Type IsNotAssignableToType([ValidatedNotNull]Type param, Type nonExpectedType, [InvokerParameterName] string paramName = null, OptsFn optsFn = null) + public Type IsNotAssignableToType([ValidatedNotNull, NotNull]Type param, Type nonExpectedType, [InvokerParameterName] string paramName = null, OptsFn optsFn = null) { Ensure.Any.IsNotNull(param, paramName, optsFn); Ensure.Any.IsNotNull(nonExpectedType, nameof(nonExpectedType)); @@ -224,9 +226,9 @@ public Type IsNotAssignableToType([ValidatedNotNull]Type param, Type nonExpected return param; } - [NotNull] + [return: NotNull] [ContractAnnotation("param:null => halt")] - public T IsClass([ValidatedNotNull]T param, [InvokerParameterName] string paramName = null, OptsFn optsFn = null) + public T IsClass([ValidatedNotNull, NotNull]T param, [InvokerParameterName] string paramName = null, OptsFn optsFn = null) { if (param == null) throw Ensure.ExceptionFactory.ArgumentNullException( @@ -239,9 +241,9 @@ public T IsClass([ValidatedNotNull]T param, [InvokerParameterName] string par return param; } - [NotNull] + [return: NotNull] [ContractAnnotation("param:null => halt")] - public Type IsClass([ValidatedNotNull]Type param, [InvokerParameterName] string paramName = null, OptsFn optsFn = null) + public Type IsClass([ValidatedNotNull, NotNull]Type param, [InvokerParameterName] string paramName = null, OptsFn optsFn = null) { if (param == null) throw Ensure.ExceptionFactory.ArgumentNullException( @@ -258,4 +260,4 @@ public Type IsClass([ValidatedNotNull]Type param, [InvokerParameterName] string return param; } } -} \ No newline at end of file +} diff --git a/src/projects/EnsureThat/Ensure.cs b/src/projects/EnsureThat/Ensure.cs index 40c926df..30eaf1c6 100644 --- a/src/projects/EnsureThat/Ensure.cs +++ b/src/projects/EnsureThat/Ensure.cs @@ -1,4 +1,4 @@ -using System; +using System; using EnsureThat.Enforcers; using EnsureThat.Internals; using JetBrains.Annotations; diff --git a/src/projects/EnsureThat/EnsureArg.Any.cs b/src/projects/EnsureThat/EnsureArg.Any.cs index 791b5dea..89bf5ac3 100644 --- a/src/projects/EnsureThat/EnsureArg.Any.cs +++ b/src/projects/EnsureThat/EnsureArg.Any.cs @@ -2,6 +2,8 @@ using EnsureThat.Annotations; using JetBrains.Annotations; +using NotNullAttribute = System.Diagnostics.CodeAnalysis.NotNullAttribute; + namespace EnsureThat { public static partial class EnsureArg @@ -18,14 +20,14 @@ public static partial class EnsureArg /// /// /// If you know you are dealing with e.g. a struct, the overload is more performant. - [NotNull] + [return: NotNull] [ContractAnnotation("value:null => halt")] - public static T HasValue([NoEnumeration, ValidatedNotNull] T value, [InvokerParameterName] string paramName = null, OptsFn optsFn = null) + public static T HasValue([NoEnumeration, ValidatedNotNull, NotNull] T value, [InvokerParameterName] string paramName = null, OptsFn optsFn = null) => Ensure.Any.HasValue(value, paramName, optsFn); - [NotNull] + [return: NotNull] [ContractAnnotation("value:null => halt")] - public static T IsNotNull([NoEnumeration, ValidatedNotNull] T value, [InvokerParameterName] string paramName = null, OptsFn optsFn = null) where T : class + public static T IsNotNull([NoEnumeration, ValidatedNotNull, NotNull] T value, [InvokerParameterName] string paramName = null, OptsFn optsFn = null) where T : class => Ensure.Any.IsNotNull(value, paramName, optsFn); } -} \ No newline at end of file +} diff --git a/src/projects/EnsureThat/EnsureArg.Collections.cs b/src/projects/EnsureThat/EnsureArg.Collections.cs index dc4d5b88..c72cfec7 100644 --- a/src/projects/EnsureThat/EnsureArg.Collections.cs +++ b/src/projects/EnsureThat/EnsureArg.Collections.cs @@ -4,118 +4,120 @@ using EnsureThat.Annotations; using JetBrains.Annotations; +using NotNullAttribute = System.Diagnostics.CodeAnalysis.NotNullAttribute; + namespace EnsureThat { public static partial class EnsureArg { - [NotNull] + [return: NotNull] [ContractAnnotation("value:null => halt")] - public static T HasItems([ValidatedNotNull] T value, [InvokerParameterName] string paramName = null, OptsFn optsFn = null) where T : class, ICollection + public static T HasItems([ValidatedNotNull, NotNull] T value, [InvokerParameterName] string paramName = null, OptsFn optsFn = null) where T : class, ICollection => Ensure.Collection.HasItems(value, paramName, optsFn); - [NotNull] + [return: NotNull] [ContractAnnotation("value:null => halt")] - public static ICollection HasItems([ValidatedNotNull]ICollection value, [InvokerParameterName] string paramName = null, OptsFn optsFn = null) + public static ICollection HasItems([ValidatedNotNull, NotNull]ICollection value, [InvokerParameterName] string paramName = null, OptsFn optsFn = null) => Ensure.Collection.HasItems(value, paramName, optsFn); - [NotNull] + [return: NotNull] [ContractAnnotation("value:null => halt")] - public static IReadOnlyCollection HasItems([ValidatedNotNull]IReadOnlyCollection value, [InvokerParameterName] string paramName = null, OptsFn optsFn = null) + public static IReadOnlyCollection HasItems([ValidatedNotNull, NotNull]IReadOnlyCollection value, [InvokerParameterName] string paramName = null, OptsFn optsFn = null) => Ensure.Collection.HasItems(value, paramName, optsFn); - [NotNull] + [return: NotNull] [ContractAnnotation("value:null => halt")] - public static IReadOnlyList HasItems([ValidatedNotNull]IReadOnlyList value, [InvokerParameterName] string paramName = null, OptsFn optsFn = null) + public static IReadOnlyList HasItems([ValidatedNotNull, NotNull]IReadOnlyList value, [InvokerParameterName] string paramName = null, OptsFn optsFn = null) => Ensure.Collection.HasItems(value, paramName, optsFn); - [NotNull] + [return: NotNull] [ContractAnnotation("value:null => halt")] - public static ISet HasItems([ValidatedNotNull]ISet value, [InvokerParameterName] string paramName = null, OptsFn optsFn = null) + public static ISet HasItems([ValidatedNotNull, NotNull]ISet value, [InvokerParameterName] string paramName = null, OptsFn optsFn = null) => Ensure.Collection.HasItems(value, paramName, optsFn); - [NotNull] + [return: NotNull] [ContractAnnotation("value:null => halt")] - public static T[] HasItems([ValidatedNotNull]T[] value, [InvokerParameterName] string paramName = null, OptsFn optsFn = null) + public static T[] HasItems([ValidatedNotNull, NotNull]T[] value, [InvokerParameterName] string paramName = null, OptsFn optsFn = null) => Ensure.Collection.HasItems(value, paramName, optsFn); - [NotNull] + [return: NotNull] [ContractAnnotation("value:null => halt")] - public static IList HasItems([ValidatedNotNull] IList value, [InvokerParameterName] string paramName = null, OptsFn optsFn = null) + public static IList HasItems([ValidatedNotNull, NotNull] IList value, [InvokerParameterName] string paramName = null, OptsFn optsFn = null) => Ensure.Collection.HasItems(value, paramName, optsFn); - [NotNull] + [return: NotNull] [ContractAnnotation("value:null => halt")] - public static IDictionary HasItems([ValidatedNotNull]IDictionary value, [InvokerParameterName] string paramName = null, OptsFn optsFn = null) + public static IDictionary HasItems([ValidatedNotNull, NotNull]IDictionary value, [InvokerParameterName] string paramName = null, OptsFn optsFn = null) => Ensure.Collection.HasItems(value, paramName, optsFn); - [NotNull] + [return: NotNull] [ContractAnnotation("value:null => halt")] - public static T[] SizeIs([ValidatedNotNull]T[] value, int expected, [InvokerParameterName] string paramName = null, OptsFn optsFn = null) + public static T[] SizeIs([ValidatedNotNull, NotNull]T[] value, int expected, [InvokerParameterName] string paramName = null, OptsFn optsFn = null) => Ensure.Collection.SizeIs(value, expected, paramName, optsFn); - [NotNull] + [return: NotNull] [ContractAnnotation("value:null => halt")] - public static T[] SizeIs([ValidatedNotNull]T[] value, long expected, [InvokerParameterName] string paramName = null, OptsFn optsFn = null) + public static T[] SizeIs([ValidatedNotNull, NotNull]T[] value, long expected, [InvokerParameterName] string paramName = null, OptsFn optsFn = null) => Ensure.Collection.SizeIs(value, expected, paramName, optsFn); - [NotNull] + [return: NotNull] [ContractAnnotation("value:null => halt")] - public static T SizeIs([ValidatedNotNull]T value, int expected, [InvokerParameterName] string paramName = null, OptsFn optsFn = null) where T : class, ICollection + public static T SizeIs([ValidatedNotNull, NotNull]T value, int expected, [InvokerParameterName] string paramName = null, OptsFn optsFn = null) where T : class, ICollection => Ensure.Collection.SizeIs(value, expected, paramName, optsFn); - [NotNull] + [return: NotNull] [ContractAnnotation("value:null => halt")] - public static T SizeIs([ValidatedNotNull]T value, long expected, [InvokerParameterName] string paramName = null, OptsFn optsFn = null) where T : class, ICollection + public static T SizeIs([ValidatedNotNull, NotNull]T value, long expected, [InvokerParameterName] string paramName = null, OptsFn optsFn = null) where T : class, ICollection => Ensure.Collection.SizeIs(value, expected, paramName, optsFn); - [NotNull] + [return: NotNull] [ContractAnnotation("value:null => halt")] - public static ICollection SizeIs([ValidatedNotNull]ICollection value, int expected, [InvokerParameterName] string paramName = null, OptsFn optsFn = null) + public static ICollection SizeIs([ValidatedNotNull, NotNull]ICollection value, int expected, [InvokerParameterName] string paramName = null, OptsFn optsFn = null) => Ensure.Collection.SizeIs(value, expected, paramName, optsFn); - [NotNull] + [return: NotNull] [ContractAnnotation("value:null => halt")] - public static ICollection SizeIs([ValidatedNotNull]ICollection value, long expected, [InvokerParameterName] string paramName = null, OptsFn optsFn = null) + public static ICollection SizeIs([ValidatedNotNull, NotNull]ICollection value, long expected, [InvokerParameterName] string paramName = null, OptsFn optsFn = null) => Ensure.Collection.SizeIs(value, expected, paramName, optsFn); - [NotNull] + [return: NotNull] [ContractAnnotation("value:null => halt")] - public static IList SizeIs([ValidatedNotNull] IList value, int expected, [InvokerParameterName] string paramName = null, OptsFn optsFn = null) + public static IList SizeIs([ValidatedNotNull, NotNull] IList value, int expected, [InvokerParameterName] string paramName = null, OptsFn optsFn = null) => Ensure.Collection.SizeIs(value, expected, paramName, optsFn); - [NotNull] + [return: NotNull] [ContractAnnotation("value:null => halt")] - public static IList SizeIs([ValidatedNotNull]IList value, long expected, [InvokerParameterName] string paramName = null, OptsFn optsFn = null) + public static IList SizeIs([ValidatedNotNull, NotNull]IList value, long expected, [InvokerParameterName] string paramName = null, OptsFn optsFn = null) => Ensure.Collection.SizeIs(value, expected, paramName, optsFn); - [NotNull] + [return: NotNull] [ContractAnnotation("value:null => halt")] - public static IDictionary SizeIs([ValidatedNotNull]IDictionary value, int expected, [InvokerParameterName] string paramName = null, OptsFn optsFn = null) + public static IDictionary SizeIs([ValidatedNotNull, NotNull]IDictionary value, int expected, [InvokerParameterName] string paramName = null, OptsFn optsFn = null) => Ensure.Collection.SizeIs(value, expected, paramName, optsFn); - [NotNull] + [return: NotNull] [ContractAnnotation("value:null => halt")] - public static IDictionary SizeIs([ValidatedNotNull]IDictionary value, long expected, [InvokerParameterName] string paramName = null, OptsFn optsFn = null) + public static IDictionary SizeIs([ValidatedNotNull, NotNull]IDictionary value, long expected, [InvokerParameterName] string paramName = null, OptsFn optsFn = null) => Ensure.Collection.SizeIs(value, expected, paramName, optsFn); - [NotNull] + [return: NotNull] [ContractAnnotation("value:null => halt")] - public static IDictionary ContainsKey([ValidatedNotNull]IDictionary value, TKey expectedKey, [InvokerParameterName] string paramName = null, OptsFn optsFn = null) + public static IDictionary ContainsKey([ValidatedNotNull, NotNull]IDictionary value, TKey expectedKey, [InvokerParameterName] string paramName = null, OptsFn optsFn = null) => Ensure.Collection.ContainsKey(value, expectedKey, paramName, optsFn); - [NotNull] + [return: NotNull] [ContractAnnotation("value:null => halt")] - public static IList HasAny([ValidatedNotNull] IList value, Func predicate, [InvokerParameterName] string paramName = null, OptsFn optsFn = null) + public static IList HasAny([ValidatedNotNull, NotNull] IList value, Func predicate, [InvokerParameterName] string paramName = null, OptsFn optsFn = null) => Ensure.Collection.HasAny(value, predicate, paramName, optsFn); - [NotNull] + [return: NotNull] [ContractAnnotation("value:null => halt")] - public static ICollection HasAny([ValidatedNotNull]ICollection value, Func predicate, [InvokerParameterName] string paramName = null, OptsFn optsFn = null) + public static ICollection HasAny([ValidatedNotNull, NotNull]ICollection value, Func predicate, [InvokerParameterName] string paramName = null, OptsFn optsFn = null) => Ensure.Collection.HasAny(value, predicate, paramName, optsFn); - [NotNull] + [return: NotNull] [ContractAnnotation("value:null => halt")] - public static T[] HasAny([ValidatedNotNull]T[] value, Func predicate, [InvokerParameterName] string paramName = null, OptsFn optsFn = null) + public static T[] HasAny([ValidatedNotNull, NotNull]T[] value, Func predicate, [InvokerParameterName] string paramName = null, OptsFn optsFn = null) => Ensure.Collection.HasAny(value, predicate, paramName, optsFn); } -} \ No newline at end of file +} diff --git a/src/projects/EnsureThat/EnsureArg.Strings.cs b/src/projects/EnsureThat/EnsureArg.Strings.cs index 42b3d508..33ec95a7 100644 --- a/src/projects/EnsureThat/EnsureArg.Strings.cs +++ b/src/projects/EnsureThat/EnsureArg.Strings.cs @@ -1,25 +1,27 @@ -using System; +using System; using System.Text.RegularExpressions; using EnsureThat.Annotations; using JetBrains.Annotations; +using NotNullAttribute = System.Diagnostics.CodeAnalysis.NotNullAttribute; + namespace EnsureThat { public static partial class EnsureArg { - [NotNull] + [return: NotNull] [ContractAnnotation("value:null => halt")] - public static string IsNotNull([ValidatedNotNull] string value, [InvokerParameterName] string paramName = null, OptsFn optsFn = null) + public static string IsNotNull([ValidatedNotNull, NotNull] string value, [InvokerParameterName] string paramName = null, OptsFn optsFn = null) => Ensure.String.IsNotNull(value, paramName, optsFn); - [NotNull] + [return: NotNull] [ContractAnnotation("value:null => halt")] - public static string IsNotNullOrWhiteSpace([ValidatedNotNull] string value, [InvokerParameterName] string paramName = null, OptsFn optsFn = null) + public static string IsNotNullOrWhiteSpace([ValidatedNotNull, NotNull] string value, [InvokerParameterName] string paramName = null, OptsFn optsFn = null) => Ensure.String.IsNotNullOrWhiteSpace(value, paramName, optsFn); - [NotNull] + [return: NotNull] [ContractAnnotation("value:null => halt")] - public static string IsNotNullOrEmpty([ValidatedNotNull] string value, [InvokerParameterName] string paramName = null, OptsFn optsFn = null) + public static string IsNotNullOrEmpty([ValidatedNotNull, NotNull] string value, [InvokerParameterName] string paramName = null, OptsFn optsFn = null) => Ensure.String.IsNotNullOrEmpty(value, paramName, optsFn); public static string IsNotEmptyOrWhiteSpace(string value, [InvokerParameterName] string paramName = null, OptsFn optsFn = null) @@ -28,28 +30,28 @@ public static string IsNotEmptyOrWhiteSpace(string value, [InvokerParameterName] public static string IsNotEmpty(string value, [InvokerParameterName] string paramName = null, OptsFn optsFn = null) => Ensure.String.IsNotEmpty(value, paramName, optsFn); - [NotNull] + [return: NotNull] [ContractAnnotation("value:null => halt")] - public static string HasLength([ValidatedNotNull] string value, int expected, [InvokerParameterName] string paramName = null, OptsFn optsFn = null) + public static string HasLength([ValidatedNotNull, NotNull] string value, int expected, [InvokerParameterName] string paramName = null, OptsFn optsFn = null) => Ensure.String.HasLength(value, expected, paramName, optsFn); - [NotNull] + [return: NotNull] [ContractAnnotation("value:null => halt")] - public static string HasLengthBetween([ValidatedNotNull] string value, int minLength, int maxLength, [InvokerParameterName] string paramName = null, OptsFn optsFn = null) + public static string HasLengthBetween([ValidatedNotNull, NotNull] string value, int minLength, int maxLength, [InvokerParameterName] string paramName = null, OptsFn optsFn = null) => Ensure.String.HasLengthBetween(value, minLength, maxLength, paramName, optsFn); - [NotNull] + [return: NotNull] public static string Matches([NotNull] string value, [NotNull] [RegexPattern] string match, [InvokerParameterName] string paramName = null, OptsFn optsFn = null) => Ensure.String.Matches(value, match, paramName, optsFn); - [NotNull] + [return: NotNull] public static string Matches([NotNull] string value, [NotNull] Regex match, [InvokerParameterName] string paramName = null, OptsFn optsFn = null) => Ensure.String.Matches(value, match, paramName, optsFn); - [NotNull] + [return: NotNull] [ContractAnnotation("value:null => halt")] [Obsolete("Use 'HasLength' instead. This will be removed in an upcoming version.")] - public static string SizeIs([ValidatedNotNull] string value, int expected, [InvokerParameterName] string paramName = null, OptsFn optsFn = null) + public static string SizeIs([ValidatedNotNull, NotNull] string value, int expected, [InvokerParameterName] string paramName = null, OptsFn optsFn = null) => Ensure.String.SizeIs(value, expected, paramName, optsFn); public static string Is(string value, string expected, [InvokerParameterName] string paramName = null, OptsFn optsFn = null) @@ -76,24 +78,24 @@ public static string IsNot(string value, string notExpected, StringComparison co public static string IsNotEqualTo(string value, string notExpected, StringComparison comparison, [InvokerParameterName] string paramName = null, OptsFn optsFn = null) => Ensure.String.IsNotEqualTo(value, notExpected, comparison, paramName, optsFn); - [NotNull] + [return: NotNull] [ContractAnnotation("value:null => halt")] - public static Guid IsGuid([ValidatedNotNull] string value, [InvokerParameterName] string paramName = null, OptsFn optsFn = null) + public static Guid IsGuid([ValidatedNotNull, NotNull] string value, [InvokerParameterName] string paramName = null, OptsFn optsFn = null) => Ensure.String.IsGuid(value, paramName, optsFn); - [NotNull] + [return: NotNull] [ContractAnnotation("value:null => halt")] - public static string StartsWith([ValidatedNotNull] string value, [NotNull] string expectedStartsWith, [InvokerParameterName] string paramName = null, OptsFn optsFn = null) + public static string StartsWith([ValidatedNotNull, NotNull] string value, [NotNull] string expectedStartsWith, [InvokerParameterName] string paramName = null, OptsFn optsFn = null) => Ensure.String.StartsWith(value, expectedStartsWith, paramName, optsFn); - [NotNull] + [return: NotNull] [ContractAnnotation("value:null => halt")] - public static string StartsWith([ValidatedNotNull] string value, [NotNull] string expectedStartsWith, StringComparison comparisonType, [InvokerParameterName] string paramName = null, OptsFn optsFn = null) + public static string StartsWith([ValidatedNotNull, NotNull] string value, [NotNull] string expectedStartsWith, StringComparison comparisonType, [InvokerParameterName] string paramName = null, OptsFn optsFn = null) => Ensure.String.StartsWith(value, expectedStartsWith, comparisonType, paramName, optsFn); - [NotNull] + [return: NotNull] [ContractAnnotation("value:null => halt")] - public static string IsAllLettersOrDigits([ValidatedNotNull] string value, [InvokerParameterName] string paramName = null, OptsFn optsFn = null) + public static string IsAllLettersOrDigits([ValidatedNotNull, NotNull] string value, [InvokerParameterName] string paramName = null, OptsFn optsFn = null) => Ensure.String.IsAllLettersOrDigits(value, paramName, optsFn); } -} \ No newline at end of file +} diff --git a/src/projects/EnsureThat/EnsureArg.Types.cs b/src/projects/EnsureThat/EnsureArg.Types.cs index 2fb1fa5f..808b9d42 100644 --- a/src/projects/EnsureThat/EnsureArg.Types.cs +++ b/src/projects/EnsureThat/EnsureArg.Types.cs @@ -2,138 +2,140 @@ using EnsureThat.Annotations; using JetBrains.Annotations; +using NotNullAttribute = System.Diagnostics.CodeAnalysis.NotNullAttribute; + namespace EnsureThat { public static partial class EnsureArg { - [NotNull] + [return: NotNull] [ContractAnnotation("param:null => halt")] - public static Type IsInt([ValidatedNotNull]Type param, [InvokerParameterName] string paramName = null, OptsFn optsFn = null) + public static Type IsInt([ValidatedNotNull, NotNull]Type param, [InvokerParameterName] string paramName = null, OptsFn optsFn = null) => Ensure.Type.IsInt(param, paramName, optsFn); - [NotNull] + [return: NotNull] [ContractAnnotation("param:null => halt")] - public static object IsInt([ValidatedNotNull]object param, [InvokerParameterName] string paramName = null, OptsFn optsFn = null) + public static object IsInt([ValidatedNotNull, NotNull]object param, [InvokerParameterName] string paramName = null, OptsFn optsFn = null) => Ensure.Type.IsInt(param, paramName, optsFn); - [NotNull] + [return: NotNull] [ContractAnnotation("param:null => halt")] - public static Type IsShort([ValidatedNotNull]Type param, [InvokerParameterName] string paramName = null, OptsFn optsFn = null) + public static Type IsShort([ValidatedNotNull, NotNull]Type param, [InvokerParameterName] string paramName = null, OptsFn optsFn = null) => Ensure.Type.IsShort(param, paramName, optsFn); - [NotNull] + [return: NotNull] [ContractAnnotation("param:null => halt")] - public static object IsShort([ValidatedNotNull]object param, [InvokerParameterName] string paramName = null, OptsFn optsFn = null) + public static object IsShort([ValidatedNotNull, NotNull]object param, [InvokerParameterName] string paramName = null, OptsFn optsFn = null) => Ensure.Type.IsShort(param, paramName, optsFn); - [NotNull] + [return: NotNull] [ContractAnnotation("param:null => halt")] - public static Type IsDecimal([ValidatedNotNull]Type param, [InvokerParameterName] string paramName = null, OptsFn optsFn = null) + public static Type IsDecimal([ValidatedNotNull, NotNull]Type param, [InvokerParameterName] string paramName = null, OptsFn optsFn = null) => Ensure.Type.IsDecimal(param, paramName, optsFn); - [NotNull] + [return: NotNull] [ContractAnnotation("param:null => halt")] - public static object IsDecimal([ValidatedNotNull]object param, [InvokerParameterName] string paramName = null, OptsFn optsFn = null) + public static object IsDecimal([ValidatedNotNull, NotNull]object param, [InvokerParameterName] string paramName = null, OptsFn optsFn = null) => Ensure.Type.IsDecimal(param, paramName, optsFn); - [NotNull] + [return: NotNull] [ContractAnnotation("param:null => halt")] - public static Type IsDouble([ValidatedNotNull]Type param, [InvokerParameterName] string paramName = null, OptsFn optsFn = null) + public static Type IsDouble([ValidatedNotNull, NotNull]Type param, [InvokerParameterName] string paramName = null, OptsFn optsFn = null) => Ensure.Type.IsDouble(param, paramName, optsFn); - [NotNull] + [return: NotNull] [ContractAnnotation("param:null => halt")] - public static object IsDouble([ValidatedNotNull]object param, [InvokerParameterName] string paramName = null, OptsFn optsFn = null) + public static object IsDouble([ValidatedNotNull, NotNull]object param, [InvokerParameterName] string paramName = null, OptsFn optsFn = null) => Ensure.Type.IsDouble(param, paramName, optsFn); - [NotNull] + [return: NotNull] [ContractAnnotation("param:null => halt")] - public static Type IsFloat([ValidatedNotNull]Type param, [InvokerParameterName] string paramName = null, OptsFn optsFn = null) + public static Type IsFloat([ValidatedNotNull, NotNull]Type param, [InvokerParameterName] string paramName = null, OptsFn optsFn = null) => Ensure.Type.IsFloat(param, paramName, optsFn); - [NotNull] + [return: NotNull] [ContractAnnotation("param:null => halt")] - public static object IsFloat([ValidatedNotNull]object param, [InvokerParameterName] string paramName = null, OptsFn optsFn = null) + public static object IsFloat([ValidatedNotNull, NotNull]object param, [InvokerParameterName] string paramName = null, OptsFn optsFn = null) => Ensure.Type.IsFloat(param, paramName, optsFn); - [NotNull] + [return: NotNull] [ContractAnnotation("param:null => halt")] - public static Type IsBool([ValidatedNotNull]Type param, [InvokerParameterName] string paramName = null, OptsFn optsFn = null) + public static Type IsBool([ValidatedNotNull, NotNull]Type param, [InvokerParameterName] string paramName = null, OptsFn optsFn = null) => Ensure.Type.IsBool(param, paramName, optsFn); - [NotNull] + [return: NotNull] [ContractAnnotation("param:null => halt")] - public static object IsBool([ValidatedNotNull]object param, [InvokerParameterName] string paramName = null, OptsFn optsFn = null) + public static object IsBool([ValidatedNotNull, NotNull]object param, [InvokerParameterName] string paramName = null, OptsFn optsFn = null) => Ensure.Type.IsBool(param, paramName, optsFn); - [NotNull] + [return: NotNull] [ContractAnnotation("param:null => halt")] - public static Type IsDateTime([ValidatedNotNull]Type param, [InvokerParameterName] string paramName = null, OptsFn optsFn = null) + public static Type IsDateTime([ValidatedNotNull, NotNull]Type param, [InvokerParameterName] string paramName = null, OptsFn optsFn = null) => Ensure.Type.IsDateTime(param, paramName, optsFn); - [NotNull] + [return: NotNull] [ContractAnnotation("param:null => halt")] - public static object IsDateTime([ValidatedNotNull]object param, [InvokerParameterName] string paramName = null, OptsFn optsFn = null) + public static object IsDateTime([ValidatedNotNull, NotNull]object param, [InvokerParameterName] string paramName = null, OptsFn optsFn = null) => Ensure.Type.IsDateTime(param, paramName, optsFn); - [NotNull] + [return: NotNull] [ContractAnnotation("param:null => halt")] - public static Type IsString([ValidatedNotNull]Type param, [InvokerParameterName] string paramName = null, OptsFn optsFn = null) + public static Type IsString([ValidatedNotNull, NotNull]Type param, [InvokerParameterName] string paramName = null, OptsFn optsFn = null) => Ensure.Type.IsString(param, paramName, optsFn); - [NotNull] + [return: NotNull] [ContractAnnotation("param:null => halt")] - public static object IsString([ValidatedNotNull]object param, [InvokerParameterName] string paramName = null, OptsFn optsFn = null) + public static object IsString([ValidatedNotNull, NotNull]object param, [InvokerParameterName] string paramName = null, OptsFn optsFn = null) => Ensure.Type.IsString(param, paramName, optsFn); - [NotNull] + [return: NotNull] [ContractAnnotation("param:null => halt")] - public static object IsOfType([ValidatedNotNull] object param, Type expectedType, [InvokerParameterName] string paramName = null, OptsFn optsFn = null) + public static object IsOfType([ValidatedNotNull, NotNull] object param, Type expectedType, [InvokerParameterName] string paramName = null, OptsFn optsFn = null) => Ensure.Type.IsOfType(param, expectedType, paramName, optsFn); - [NotNull] + [return: NotNull] [ContractAnnotation("param:null => halt")] - public static Type IsOfType([ValidatedNotNull]Type param, Type expectedType, [InvokerParameterName] string paramName = null, OptsFn optsFn = null) + public static Type IsOfType([ValidatedNotNull, NotNull]Type param, Type expectedType, [InvokerParameterName] string paramName = null, OptsFn optsFn = null) => Ensure.Type.IsOfType(param, expectedType, paramName, optsFn); - [NotNull] + [return: NotNull] [ContractAnnotation("param:null => halt")] - public static object IsNotOfType([ValidatedNotNull]object param, Type nonExpectedType, [InvokerParameterName] string paramName = null, OptsFn optsFn = null) + public static object IsNotOfType([ValidatedNotNull, NotNull]object param, Type nonExpectedType, [InvokerParameterName] string paramName = null, OptsFn optsFn = null) => Ensure.Type.IsNotOfType(param, nonExpectedType, paramName, optsFn); - [NotNull] + [return: NotNull] [ContractAnnotation("param:null => halt")] - public static Type IsNotOfType([ValidatedNotNull]Type param, Type nonExpectedType, [InvokerParameterName] string paramName = null, OptsFn optsFn = null) + public static Type IsNotOfType([ValidatedNotNull, NotNull]Type param, Type nonExpectedType, [InvokerParameterName] string paramName = null, OptsFn optsFn = null) => Ensure.Type.IsNotOfType(param, nonExpectedType, paramName, optsFn); - [NotNull] + [return: NotNull] [ContractAnnotation("param:null => halt")] - public static object IsAssignableToType([ValidatedNotNull] object param, Type expectedType, [InvokerParameterName] string paramName = null, OptsFn optsFn = null) + public static object IsAssignableToType([ValidatedNotNull, NotNull] object param, Type expectedType, [InvokerParameterName] string paramName = null, OptsFn optsFn = null) => Ensure.Type.IsAssignableToType(param, expectedType, paramName, optsFn); - [NotNull] + [return: NotNull] [ContractAnnotation("param:null => halt")] - public static Type IsAssignableToType([ValidatedNotNull]Type param, Type expectedType, [InvokerParameterName] string paramName = null, OptsFn optsFn = null) + public static Type IsAssignableToType([ValidatedNotNull, NotNull]Type param, Type expectedType, [InvokerParameterName] string paramName = null, OptsFn optsFn = null) => Ensure.Type.IsAssignableToType(param, expectedType, paramName, optsFn); - [NotNull] + [return: NotNull] [ContractAnnotation("param:null => halt")] - public static object IsNotAssignableToType([ValidatedNotNull]object param, Type nonExpectedType, [InvokerParameterName] string paramName = null, OptsFn optsFn = null) + public static object IsNotAssignableToType([ValidatedNotNull, NotNull]object param, Type nonExpectedType, [InvokerParameterName] string paramName = null, OptsFn optsFn = null) => Ensure.Type.IsNotAssignableToType(param, nonExpectedType, paramName, optsFn); - [NotNull] + [return: NotNull] [ContractAnnotation("param:null => halt")] - public static Type IsNotAssignableToType([ValidatedNotNull]Type param, Type nonExpectedType, [InvokerParameterName] string paramName = null, OptsFn optsFn = null) + public static Type IsNotAssignableToType([ValidatedNotNull, NotNull]Type param, Type nonExpectedType, [InvokerParameterName] string paramName = null, OptsFn optsFn = null) => Ensure.Type.IsNotAssignableToType(param, nonExpectedType, paramName, optsFn); - [NotNull] + [return: NotNull] [ContractAnnotation("param:null => halt")] - public static object IsClass([ValidatedNotNull]object param, [InvokerParameterName] string paramName = null, OptsFn optsFn = null) + public static object IsClass([ValidatedNotNull, NotNull]object param, [InvokerParameterName] string paramName = null, OptsFn optsFn = null) => Ensure.Type.IsClass(param, paramName, optsFn); - [NotNull] + [return: NotNull] [ContractAnnotation("param:null => halt")] - public static Type IsClass([ValidatedNotNull]Type param, [InvokerParameterName] string paramName = null, OptsFn optsFn = null) + public static Type IsClass([ValidatedNotNull, NotNull]Type param, [InvokerParameterName] string paramName = null, OptsFn optsFn = null) => Ensure.Type.IsClass(param, paramName, optsFn); } -} \ No newline at end of file +} diff --git a/src/projects/EnsureThat/EnsureThat.csproj b/src/projects/EnsureThat/EnsureThat.csproj index 7ab0b36d..c22dfdce 100644 --- a/src/projects/EnsureThat/EnsureThat.csproj +++ b/src/projects/EnsureThat/EnsureThat.csproj @@ -1,7 +1,7 @@ - + - net4.5.1;netstandard1.1;netstandard2.0 + net4.5.1;netstandard1.1;netstandard2.0;netstandard2.1 Ensure.That Ensure.That ensure-that ensure that argument validation guard clause contracts diff --git a/src/projects/EnsureThat/Internals/ExceptionFactory.cs b/src/projects/EnsureThat/Internals/ExceptionFactory.cs index 8b0fc879..8005370f 100644 --- a/src/projects/EnsureThat/Internals/ExceptionFactory.cs +++ b/src/projects/EnsureThat/Internals/ExceptionFactory.cs @@ -1,11 +1,13 @@ using System; using JetBrains.Annotations; +using NotNullAttribute = System.Diagnostics.CodeAnalysis.NotNullAttribute; + namespace EnsureThat.Internals { internal sealed class ExceptionFactory : IExceptionFactory { - [NotNull] + [return: NotNull] [Pure] public Exception ArgumentException(string defaultMessage, string paramName, OptsFn optsFn = null) { @@ -23,7 +25,7 @@ public Exception ArgumentException(string defaultMessage, string paramName, Opts return new ArgumentException(defaultMessage, paramName); } - [NotNull] + [return: NotNull] [Pure] public Exception ArgumentNullException(string defaultMessage, string paramName, OptsFn optsFn = null) { @@ -44,7 +46,7 @@ public Exception ArgumentNullException(string defaultMessage, string paramName, return new ArgumentNullException(paramName, defaultMessage); } - [NotNull] + [return: NotNull] [Pure] public Exception ArgumentOutOfRangeException(string defaultMessage, string paramName, TValue value, OptsFn optsFn = null) { diff --git a/src/projects/EnsureThat/Param.cs b/src/projects/EnsureThat/Param.cs index bfe64238..7ce75899 100644 --- a/src/projects/EnsureThat/Param.cs +++ b/src/projects/EnsureThat/Param.cs @@ -45,4 +45,4 @@ public TypeParam(string name, [NotNull] Type type, OptsFn optsFn = null) OptsFn = optsFn; } } -} \ No newline at end of file +}