Skip to content

Commit cc004d0

Browse files
committed
- added RuntimeAssemblies
1 parent e38ff77 commit cc004d0

File tree

5 files changed

+23
-8
lines changed

5 files changed

+23
-8
lines changed

Shuttle.Core.Reflection/.build/package.nuspec

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
<tags>shuttle reflection</tags>
1717
<dependencies>
1818
<dependency id="Shuttle.Core.Logging" version="{Shuttle.Core.Logging-version}" />
19+
<dependency id="Microsoft.Extensions.DependencyModel" version="{Microsoft.Extensions.DependencyModel-version}" />
1920
</dependencies>
2021
</metadata>
2122
</package>

Shuttle.Core.Reflection/IReflectionService.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ public interface IReflectionService
1313
IEnumerable<Assembly> GetAssemblies();
1414
IEnumerable<Assembly> GetMatchingAssemblies(string regex, string folder);
1515
IEnumerable<Assembly> GetMatchingAssemblies(string regex);
16+
IEnumerable<Assembly> RuntimeAssemblies();
1617
IEnumerable<Type> GetTypes<T>();
1718
IEnumerable<Type> GetTypes(Type type);
1819
IEnumerable<Type> GetTypes(Assembly assembly);

Shuttle.Core.Reflection/Properties/AssemblyInfo.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,10 +29,10 @@
2929
[assembly: AssemblyTitle(".NET Standard 2.0")]
3030
#endif
3131

32-
[assembly: AssemblyVersion("10.0.4.0")]
32+
[assembly: AssemblyVersion("10.0.5.0")]
3333
[assembly: AssemblyCopyright("Copyright © Eben Roux 2017")]
3434
[assembly: AssemblyProduct("Shuttle.Core.Reflection")]
3535
[assembly: AssemblyCompany("Shuttle")]
3636
[assembly: AssemblyConfiguration("Release")]
37-
[assembly: AssemblyInformationalVersion("10.0.4")]
37+
[assembly: AssemblyInformationalVersion("10.0.5")]
3838
[assembly: ComVisible(false)]

Shuttle.Core.Reflection/ReflectionService.cs

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44
using System.Linq;
55
using System.Reflection;
66
using System.Text.RegularExpressions;
7+
using Microsoft.DotNet.PlatformAbstractions;
8+
using Microsoft.Extensions.DependencyModel;
79
using Shuttle.Core.Contract;
810
using Shuttle.Core.Logging;
911

@@ -35,7 +37,7 @@ public string AssemblyPath(Assembly assembly)
3537

3638
public Assembly GetAssembly(string assemblyPath)
3739
{
38-
var result = AppDomain.CurrentDomain.GetAssemblies()
40+
var result = RuntimeAssemblies()
3941
.FirstOrDefault(assembly => AssemblyPath(assembly)
4042
.Equals(assemblyPath, StringComparison.InvariantCultureIgnoreCase));
4143

@@ -102,7 +104,7 @@ public Assembly FindAssemblyNamed(string name)
102104
hasFileExtension = true;
103105
}
104106

105-
var result = AppDomain.CurrentDomain.GetAssemblies()
107+
var result = RuntimeAssemblies()
106108
.FirstOrDefault(assembly => assembly.GetName()
107109
.Name.Equals(assemblyName, StringComparison.InvariantCultureIgnoreCase));
108110

@@ -186,9 +188,7 @@ private IEnumerable<Assembly> GetMatchingAssemblies(Regex expression, string fol
186188

187189
public IEnumerable<Assembly> GetMatchingAssemblies(string regex)
188190
{
189-
var expression = new Regex(regex, RegexOptions.IgnoreCase);
190-
var assemblies = new List<Assembly>(AppDomain.CurrentDomain.GetAssemblies()
191-
.Where(assembly => expression.IsMatch(assembly.FullName)));
191+
var assemblies = new List<Assembly>(RuntimeAssemblies());
192192

193193
foreach (
194194
var assembly in
@@ -215,7 +215,19 @@ var assembly in
215215
return assemblies;
216216
}
217217

218-
public IEnumerable<Type> GetTypes<T>()
218+
public IEnumerable<Assembly> RuntimeAssemblies()
219+
{
220+
var result = new List<Assembly>();
221+
222+
foreach (var runtimeAssemblyName in DependencyContext.Default.GetRuntimeAssemblyNames(RuntimeEnvironment.GetRuntimeIdentifier()))
223+
{
224+
result.Add(Assembly.Load(runtimeAssemblyName));
225+
}
226+
227+
return result;
228+
}
229+
230+
public IEnumerable<Type> GetTypes<T>()
219231
{
220232
return GetTypes(typeof(T));
221233
}

Shuttle.Core.Reflection/Shuttle.Core.Reflection.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
</ItemGroup>
1414

1515
<ItemGroup>
16+
<PackageReference Include="Microsoft.Extensions.DependencyModel" Version="2.0.4" />
1617
<PackageReference Include="Shuttle.Core.Logging" Version="10.0.1" />
1718
</ItemGroup>
1819

0 commit comments

Comments
 (0)