mirror of
https://github.com/ICDSystems/ICD.Common.Utils.git
synced 2026-02-17 13:45:05 +00:00
Load existing assemblies by name
This commit is contained in:
@@ -2,7 +2,6 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
|
|
||||||
using Crestron.SimplSharp.Reflection;
|
using Crestron.SimplSharp.Reflection;
|
||||||
|
|
||||||
namespace ICD.Common.Utils.Extensions
|
namespace ICD.Common.Utils.Extensions
|
||||||
|
|||||||
@@ -2,7 +2,9 @@
|
|||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using ICD.Common.Properties;
|
using ICD.Common.Properties;
|
||||||
|
using ICD.Common.Utils.IO;
|
||||||
#if SIMPLSHARP
|
#if SIMPLSHARP
|
||||||
|
using Crestron.SimplSharp.CrestronIO;
|
||||||
using Crestron.SimplSharp.Reflection;
|
using Crestron.SimplSharp.Reflection;
|
||||||
using Activator = Crestron.SimplSharp.Reflection.Activator;
|
using Activator = Crestron.SimplSharp.Reflection.Activator;
|
||||||
#else
|
#else
|
||||||
@@ -234,11 +236,29 @@ namespace ICD.Common.Utils
|
|||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
public static Assembly LoadAssemblyFromPath(string path)
|
public static Assembly LoadAssemblyFromPath(string path)
|
||||||
{
|
{
|
||||||
#if SIMPLSHARP
|
if (path == null)
|
||||||
return Assembly.LoadFrom(path);
|
throw new ArgumentNullException("path");
|
||||||
#else
|
|
||||||
string fileNameWithOutExtension = Path.GetFileNameWithoutExtension(path);
|
|
||||||
|
|
||||||
|
if (string.IsNullOrEmpty(path))
|
||||||
|
throw new ArgumentException("Path is empty", "path");
|
||||||
|
|
||||||
|
string fileNameWithOutExtension = IcdPath.GetFileNameWithoutExtension(path);
|
||||||
|
|
||||||
|
#if SIMPLSHARP
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
return Assembly.Load(new AssemblyName {Name = fileNameWithOutExtension});
|
||||||
|
}
|
||||||
|
catch (IOException)
|
||||||
|
{
|
||||||
|
return Assembly.LoadFrom(path);
|
||||||
|
}
|
||||||
|
catch (FileNotFoundException)
|
||||||
|
{
|
||||||
|
return Assembly.LoadFrom(path);
|
||||||
|
}
|
||||||
|
#else
|
||||||
bool inCompileLibraries = DependencyContext.Default.CompileLibraries.Any(l => l.Name.Equals(fileNameWithOutExtension, StringComparison.OrdinalIgnoreCase));
|
bool inCompileLibraries = DependencyContext.Default.CompileLibraries.Any(l => l.Name.Equals(fileNameWithOutExtension, StringComparison.OrdinalIgnoreCase));
|
||||||
bool inRuntimeLibraries = DependencyContext.Default.RuntimeLibraries.Any(l => l.Name.Equals(fileNameWithOutExtension, StringComparison.OrdinalIgnoreCase));
|
bool inRuntimeLibraries = DependencyContext.Default.RuntimeLibraries.Any(l => l.Name.Equals(fileNameWithOutExtension, StringComparison.OrdinalIgnoreCase));
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user