feat: added assembly.GetDirectory()
This commit is contained in:
parent
202eb63a5e
commit
53aacbf862
|
@ -26,6 +26,12 @@ The repository can also be added to a project by setting the `NuGet.Config` file
|
||||||
|
|
||||||
## Extensions
|
## Extensions
|
||||||
|
|
||||||
|
### Assembly Extensions
|
||||||
|
|
||||||
|
#### `DirectoryInfo? GetDirectory(this Assembly? assembly)`
|
||||||
|
|
||||||
|
Gets a directory representing the assembly's `Location` property or null.
|
||||||
|
|
||||||
### DirectoryInfo Extensions
|
### DirectoryInfo Extensions
|
||||||
|
|
||||||
#### `DirectoryInfo? CreateIfMissing(this DirectoryInfo? directory)`
|
#### `DirectoryInfo? CreateIfMissing(this DirectoryInfo? directory)`
|
||||||
|
|
23
src/MfGames.IO/Extensions/AssemblyExtensions.cs
Normal file
23
src/MfGames.IO/Extensions/AssemblyExtensions.cs
Normal 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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
Reference in a new issue