src/packages/EmbedIO/Utilities/Validate-Paths.cs
/// <summary>
/// Ensures that the value of an argument is a valid local path
/// and, optionally, gets the corresponding full path.
/// </summary>
/// <param name="argumentName">The name of the argument to validate.</param>
/// <param name="value">The value to validate.</param>
/// <param name="getFullPath"><see langword="true"/> to get the full path, <see langword="false"/> to leave the path as is..</param>
/// <returns>The local path, or the full path if <paramref name="getFullPath"/> is <see langword="true"/>.</returns>
/// <exception cref="ArgumentNullException"><paramref name="value"/> is <see langword="null"/>.</exception>
/// <exception cref="ArgumentException">
/// <para><paramref name="value"/> is empty.</para>
/// <para>- or -</para>
/// <para><paramref name="value"/> contains only white space.</para>
/// <para>- or -</para>
/// <para><paramref name="value"/> contains one or more invalid characters.</para>
/// <para>- or -</para>
/// <para><paramref name="getFullPath"/> is <see langword="true"/> and the full path could not be obtained.</para>
/// </exception>
Ensures that the value of an argument is a valid local path
and, optionally, gets the corresponding full path.
Ensures that the value of an argument is a valid local path and optionally gets the corresponding full path .
public static string LocalPath(string argumentName, [ValidatedNotNull] string value, bool getFullPath)
        {
            if (value == null)
                throw new ArgumentNullException(argumentName);
            if (value.Length == 0)
                throw new ArgumentException("Local path is empty.", argumentName);
            if (string.IsNullOrWhiteSpace(value))
                throw new ArgumentException("Local path contains only white space.", argumentName);
            if (value.IndexOfAny(InvalidLocalPathChars) >= 0)
                throw new ArgumentException("Local path contains one or more invalid characters.", argumentName);
            if (getFullPath)
            {
                try
                {
                    value = Path.GetFullPath(value);
                }
                catch (Exception e) when (e is ArgumentException || e is SecurityException || e is NotSupportedException || e is PathTooLongException)
                {
                    throw new ArgumentException("Could not get the full local path.", argumentName, e);
                }
            }
            return value;
        }
public static string LocalPath ( string argumentName , [ ValidatedNotNull ] string value , bool getFullPath ) { if ( value == null ) throw new ArgumentNullException ( argumentName ) ; if ( value . Length == 0 ) throw new ArgumentException ( " " , argumentName ) ; if ( string . IsNullOrWhiteSpace ( value ) ) throw new ArgumentException ( " " , argumentName ) ; if ( value . IndexOfAny ( InvalidLocalPathChars ) >= 0 ) throw new ArgumentException ( " " , argumentName ) ; if ( getFullPath ) { try { value = Path . GetFullPath ( value ) ; } catch ( Exception e ) when ( e is ArgumentException || e is SecurityException || e is NotSupportedException || e is PathTooLongException ) { throw new ArgumentException ( " " , argumentName , e ) ; } } return value ; }
Ensures that the value of an argument is a valid local path
and, optionally, gets the corresponding full path.
Ensures that the value of an argument is a valid local path and optionally gets the corresponding full path .
The local path, or the full path if  is .
The local path or the full path if is .
None
None
argumentName
string
The name of the argument to validate.
The name of the argument to validate .
string
[ValidatedNotNull]
<not_specific>
getFullPath
bool
to get the full path,  to leave the path as is
to get the full path to leave the path as is
value
<not_specific>
The value to validate.
The value to validate .