예제 #1
0
		/// <summary>
		///     Try get a new <see cref="IEnvironmentVariableDirectoryPath" /> object from this string.
		/// </summary>
		/// <returns>
		///     <i>true</i> if <paramref name="path" /> is a valid directory path prefixed with an environment variable and as a consequence, the
		///     returned <paramref name="directoryPath" /> 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="directoryPath">If this method returns <i>true</i>, this is the returned path object.</param>
		public static bool TryGetEnvVarDirectoryPath(this string path, out IEnvironmentVariableDirectoryPath directoryPath)
		{
			string failureMessage;

			return path.TryGetEnvVarDirectoryPath(out directoryPath, out failureMessage);
		}
예제 #2
0
		/// <summary>
		///     Try get a new <see cref="IEnvironmentVariableDirectoryPath" /> object from this string.
		/// </summary>
		/// <returns>
		///     <i>true</i> if <paramref name="path" /> is a valid directory path prefixed with an environment variable and as a consequence, the
		///     returned <paramref name="directoryPath" /> 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="directoryPath">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 TryGetEnvVarDirectoryPath(this string path, out IEnvironmentVariableDirectoryPath directoryPath, out string failureMessage)
		{
			directoryPath = null;

			if (IsNullOrEmpty(() => path, out failureMessage))
			{
				return false;
			}

			if (!path.IsValidEnvVarDirectoryPath(out failureMessage))
			{
				return false;
			}

			directoryPath = new EnvironmentVariableDirectoryPath(path);

			return true;
		}