/// <summary> /// Try get a new <see cref="IEnvironmentVariableFilePath" /> object from this string. /// </summary> /// <returns> /// <i>true</i> if <paramref name="path" /> is a valid file path prefixed with an environment variable and as a consequence, the returned /// <paramref name="filePath" /> is not null. /// </returns> /// <remarks> /// The path represented by this string doesn't need to exist for this operation to complete properly. /// The environment variable prefixing the path doesn't need to exist for this operation to complete properly. /// </remarks> /// <param name="path">Represents the path.</param> /// <param name="filePath">If this method returns <i>true</i>, this is the returned path object.</param> public static bool TryGetEnvVarFilePath(this string path, out IEnvironmentVariableFilePath filePath) { string failureMessage; return path.TryGetEnvVarFilePath(out filePath, out failureMessage); }
/// <summary> /// Try get a new <see cref="IEnvironmentVariableFilePath" /> object from this string. /// </summary> /// <returns> /// <i>true</i> if <paramref name="path" /> is a valid file path prefixed with an environment variable and as a consequence, the returned /// <paramref name="filePath" /> is not null. /// </returns> /// <remarks> /// The path represented by this string doesn't need to exist for this operation to complete properly. /// The environment variable prefixing the path doesn't need to exist for this operation to complete properly. /// </remarks> /// <param name="path">Represents the path.</param> /// <param name="filePath">If this method returns <i>true</i>, this is the returned path object.</param> /// <param name="failureMessage">If this method returns <i>false</i>, this is the plain english description of the failure.</param> public static bool TryGetEnvVarFilePath(this string path, out IEnvironmentVariableFilePath filePath, out string failureMessage) { filePath = null; if (IsNullOrEmpty(() => path, out failureMessage)) { return false; } if (!path.IsValidEnvVarFilePath(out failureMessage)) { return false; } filePath = new EnvironmentVariableFilePath(path); return true; }