mirror of
https://github.com/ICDSystems/ICD.Common.Utils.git
synced 2026-02-16 21:24:58 +00:00
Initial commit of AssemblyExtensions
This commit is contained in:
45
ICD.Common.Utils/Extensions/AssemblyExtensions.cs
Normal file
45
ICD.Common.Utils/Extensions/AssemblyExtensions.cs
Normal 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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -112,6 +112,7 @@
|
|||||||
<Compile Include="IcdZip.cs" />
|
<Compile Include="IcdZip.cs" />
|
||||||
<Compile Include="IO\IcdDirectory.cs" />
|
<Compile Include="IO\IcdDirectory.cs" />
|
||||||
<Compile Include="EnumUtils.cs" />
|
<Compile Include="EnumUtils.cs" />
|
||||||
|
<Compile Include="Extensions\AssemblyExtensions.cs" />
|
||||||
<Compile Include="Extensions\CollectionExtensions.cs" />
|
<Compile Include="Extensions\CollectionExtensions.cs" />
|
||||||
<Compile Include="Extensions\DictionaryExtensions.cs" />
|
<Compile Include="Extensions\DictionaryExtensions.cs" />
|
||||||
<Compile Include="Extensions\EnumerableExtensions.cs" />
|
<Compile Include="Extensions\EnumerableExtensions.cs" />
|
||||||
|
|||||||
Reference in New Issue
Block a user