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