feat: added assembly.GetDirectory()

This commit is contained in:
Dylan R. E. Moonfire 2021-12-06 22:28:37 -06:00
parent 202eb63a5e
commit 53aacbf862
2 changed files with 29 additions and 0 deletions

View File

@ -26,6 +26,12 @@ The repository can also be added to a project by setting the `NuGet.Config` file
## Extensions
### Assembly Extensions
#### `DirectoryInfo? GetDirectory(this Assembly? assembly)`
Gets a directory representing the assembly's `Location` property or null.
### DirectoryInfo Extensions
#### `DirectoryInfo? CreateIfMissing(this DirectoryInfo? directory)`

View File

@ -0,0 +1,23 @@
using System.IO;
using System.Reflection;
namespace MfGames.IO.Extensions
{
/// <summary>
/// Additional methods for assemblies.
/// </summary>
public static class AssemblyExtensions
{
/// <summary>
/// Gets the directory for a given assembly.
/// </summary>
/// <param name="assembly">The assembly to get the directory.</param>
/// <returns>The directory or null if the assembly or location is null.</returns>
public static DirectoryInfo? GetDirectory(this Assembly? assembly)
{
return assembly?.Location == null
? null
: new DirectoryInfo(assembly.Location);
}
}
}