Browse Source

+guard methods

Vicente Penades 3 years ago
parent
commit
42efb8c1d6
1 changed files with 18 additions and 0 deletions
  1. 18 0
      src/Shared/Guard.cs

+ 18 - 0
src/Shared/Guard.cs

@@ -74,6 +74,24 @@ namespace SharpGLTF
             throw new ArgumentException(message, parameterName);
         }
 
+        public static void MustExist(System.IO.FileInfo finfo, string parameterName, string message = "")
+        {
+            if (finfo == null) throw new ArgumentNullException(nameof(finfo));
+            if (finfo.Exists) return;
+
+            if (string.IsNullOrWhiteSpace(message)) message = $"{finfo.FullName} is invalid or does not exist.";
+            throw new ArgumentException(message, parameterName);
+        }
+
+        public static void MustExist(System.IO.DirectoryInfo dinfo, string parameterName, string message = "")
+        {
+            if (dinfo == null) throw new ArgumentNullException(nameof(dinfo));
+            if (dinfo.Exists) return;
+
+            if (string.IsNullOrWhiteSpace(message)) message = $"{dinfo.FullName} is invalid or does not exist.";
+            throw new ArgumentException(message, parameterName);
+        }
+
         #endregion
 
         #region null / empty