From 0345543aba9245e8d00f5a2238e5ea33c7b25ab4 Mon Sep 17 00:00:00 2001 From: Chris Cameron Date: Sat, 30 Sep 2017 14:55:32 -0400 Subject: [PATCH] Initial commit of AssemblyExtensions --- .../Extensions/AssemblyExtensions.cs | 45 +++++++++++++++++++ .../ICD.Common.Utils_SimplSharp.csproj | 1 + 2 files changed, 46 insertions(+) create mode 100644 ICD.Common.Utils/Extensions/AssemblyExtensions.cs diff --git a/ICD.Common.Utils/Extensions/AssemblyExtensions.cs b/ICD.Common.Utils/Extensions/AssemblyExtensions.cs new file mode 100644 index 0000000..9c7aea1 --- /dev/null +++ b/ICD.Common.Utils/Extensions/AssemblyExtensions.cs @@ -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 + { + /// + /// Gets the path for the given assembly. Returns null if the assembly can not be found on disk. + /// + /// + /// + [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; + } + } +} diff --git a/ICD.Common.Utils/ICD.Common.Utils_SimplSharp.csproj b/ICD.Common.Utils/ICD.Common.Utils_SimplSharp.csproj index 9fe90d2..372a0c7 100644 --- a/ICD.Common.Utils/ICD.Common.Utils_SimplSharp.csproj +++ b/ICD.Common.Utils/ICD.Common.Utils_SimplSharp.csproj @@ -112,6 +112,7 @@ +