From b79c8ff7e69571f00ad09afd1708376bf31ac8f3 Mon Sep 17 00:00:00 2001
From: bparkes651 <50440953+bparkes651@users.noreply.github.com>
Date: Thu, 26 Nov 2020 09:38:43 +0000
Subject: [PATCH] Add ValidatedNotNullAttribute (#9)
This attribute suppresses code analysis warning CA1062.
---
src/Argument/Argument.cs | 6 +++---
src/Argument/ValidatedNotNullAttribute.cs | 16 ++++++++++++++++
2 files changed, 19 insertions(+), 3 deletions(-)
create mode 100644 src/Argument/ValidatedNotNullAttribute.cs
diff --git a/src/Argument/Argument.cs b/src/Argument/Argument.cs
index 75f76a7..e78c2f5 100644
--- a/src/Argument/Argument.cs
+++ b/src/Argument/Argument.cs
@@ -46,7 +46,7 @@ public static void IsInRange(bool condition, string paramName)
///
/// The object to check.
/// The name of the parameter, used in exception message if argument is null.
- public static void IsNotNull(object argument, string paramName)
+ public static void IsNotNull([ValidatedNotNull] object argument, string paramName)
{
if (argument == null)
{
@@ -59,7 +59,7 @@ public static void IsNotNull(object argument, string paramName)
///
/// The string to check.
/// The name of the parameter, used in exception message if argument is null or empty.
- public static void IsNotNullOrEmpty(string argument, string paramName)
+ public static void IsNotNullOrEmpty([ValidatedNotNull] string argument, string paramName)
{
if (argument == null)
{
@@ -77,7 +77,7 @@ public static void IsNotNullOrEmpty(string argument, string paramName)
///
/// The string to check.
/// The name of the parameter, used in exception message if argument is null or white space.
- public static void IsNotNullOrWhiteSpace(string argument, string paramName)
+ public static void IsNotNullOrWhiteSpace([ValidatedNotNull] string argument, string paramName)
{
if (argument == null)
{
diff --git a/src/Argument/ValidatedNotNullAttribute.cs b/src/Argument/ValidatedNotNullAttribute.cs
new file mode 100644
index 0000000..77242c3
--- /dev/null
+++ b/src/Argument/ValidatedNotNullAttribute.cs
@@ -0,0 +1,16 @@
+using System;
+
+namespace Enable.Common
+{
+ ///
+ /// Attribute that is appended to arguments when it has been verified
+ /// that they are not null. This suppresses code analysis warning CA1062.
+ ///
+ [AttributeUsage(AttributeTargets.Parameter)]
+ internal class ValidatedNotNullAttribute : Attribute
+ {
+ // An implementation for the attribute is not needed, as it is the name
+ // of the attribute which signals to the static analysis tool that it
+ // has been verified the argument is not null.
+ }
+}