Initial commit of AssemblyExtensions

This commit is contained in:
Chris Cameron
2017-09-30 14:55:32 -04:00
parent 1b14453603
commit 0345543aba
2 changed files with 46 additions and 0 deletions

View File

@@ -0,0 +1,45 @@
using System;
#if SIMPLSHARP
using Crestron.SimplSharp.Reflection;
#else
using System.Reflection;
#endif
using ICD.Common.Properties;
using ICD.Common.Utils.IO;
namespace ICD.Common.Utils.Extensions
{
public static class AssemblyExtensions
{
/// <summary>
/// Gets the path for the given assembly. Returns null if the assembly can not be found on disk.
/// </summary>
/// <param name="extends"></param>
/// <returns></returns>
[CanBeNull]
public static string GetPath(this Assembly extends)
{
if (extends == null)
throw new ArgumentNullException();
string path = extends
#if SIMPLSHARP
.GetName()
#endif
.CodeBase;
if (path == null)
{
path = extends.Location;
}
else
{
const string prefix = @"file:///";
if (path.StartsWith(prefix))
path = path.Substring(prefix.Length);
}
return IcdFile.Exists(path) ? path : null;
}
}
}

View File

@@ -112,6 +112,7 @@
<Compile Include="IcdZip.cs" />
<Compile Include="IO\IcdDirectory.cs" />
<Compile Include="EnumUtils.cs" />
<Compile Include="Extensions\AssemblyExtensions.cs" />
<Compile Include="Extensions\CollectionExtensions.cs" />
<Compile Include="Extensions\DictionaryExtensions.cs" />
<Compile Include="Extensions\EnumerableExtensions.cs" />