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/AssemblyExtensions.cs
2021-12-06 23:15:42 -06:00

34 lines
1.1 KiB
C#

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.GetFile()?.Directory;
}
/// <summary>
/// Gets the file 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 FileInfo? GetFile(this Assembly? assembly)
{
return assembly?.Location == null
? null
: new FileInfo(assembly.Location);
}
}
}