WGet.NET 4.4.1
A WinGet wrapper library for .Net.
Loading...
Searching...
No Matches
ArgsHelper.cs
1//--------------------------------------------------//
2// Created by basicx-StrgV //
3// https://github.com/basicx-StrgV/ //
4//--------------------------------------------------//
5using System;
6using System.IO;
7
9{
13 internal static class ArgsHelper
14 {
30 public static void ThrowIfStringIsNullOrWhiteSpace(string arg, string name)
31 {
32 if (arg == null)
33 {
34 throw new ArgumentNullException(name);
35 }
36 else if (string.IsNullOrWhiteSpace(arg))
37 {
38 throw new ArgumentException("Value cannot be empty.", name);
39 }
40 }
41
54 public static void ThrowIfObjectIsNull(object arg, string name)
55 {
56 if (arg == null)
57 {
58 throw new ArgumentNullException(name);
59 }
60 }
61
77 public static void ThrowIfWinGetObjectIsNullOrEmpty(IWinGetObject arg, string name)
78 {
79 if (arg == null)
80 {
81 throw new ArgumentNullException(name);
82 }
83 else if (arg.IsEmpty)
84 {
85 throw new ArgumentException("Object cannot be empty.", name);
86 }
87 }
88
107 public static void ThrowIfPathIsInvalid(string arg)
108 {
109 // This will indirectly throw other exeption.
110 string root = Directory.GetDirectoryRoot(arg);
111
112 // Check if the path exists.
113 if (!Directory.Exists(root))
114 {
115 throw new DirectoryNotFoundException($"The path root '{root}' does not exist.");
116 }
117 }
118 }
119}
Interface for all winget related objects.