This repository has been archived on 2023-02-02. You can view files and clone it, but cannot push or open issues or pull requests.
mfgames-io-cil/src/MfGames.IO/Extensions/DirectoryInfoExtensions.cs
Dylan R. E. Moonfire 5adb9ccc52 feat: initial commit
2021-09-11 00:54:27 -05:00

35 lines
935 B
C#

using System.IO;
namespace MfGames.IO.Extensions
{
/// <summary>
/// Useful extension methods for DirectoryInfo.
/// </summary>
public static class DirectoryInfoExtensions
{
/// <summary>
/// Makes sure a directory exists, creating it and any parents above it
/// as needed.
/// </summary>
/// <param name="directory"></param>
public static void CreateIfMissing(this DirectoryInfo? directory)
{
// Ignore blanks.
if (directory == null)
{
return;
}
// Check the parent first. We don't have to worry about null because
// we check that coming in.
directory.Parent.CreateIfMissing();
// If the directory doesn't exist, create it.
if (!directory.Exists)
{
directory.Create();
}
}
}
}