Skip to content

Commit 0e35743

Browse files
authored
Merge pull request #5 from Shuttle/v20
V20
2 parents 201b952 + 11b9d3f commit 0e35743

22 files changed

+379
-886
lines changed

README.md

Lines changed: 6 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -8,24 +8,6 @@ Provides various methods to facilitate reflection handling.
88

99
## ReflectionService
1010

11-
``` c#
12-
string AssemblyPath(Assembly assembly)
13-
```
14-
15-
Returns the path to the given assembly.
16-
17-
``` c#
18-
Task<Assembly> FindAssemblyNamedAsync(string name)
19-
```
20-
21-
Returns the `Assembly` that has the requested `name`; else `null`.
22-
23-
``` c#
24-
Task<Assembly> GetAssemblyAsync(string assemblyPath)
25-
```
26-
27-
Returns the requested assembly if found; else `null`.
28-
2911
``` c#
3012
Task<IEnumerable<Assembly>> GetMatchingAssembliesAsync(Regex regex)
3113
```
@@ -36,7 +18,7 @@ Returns a collection of assemblies that have their file name matching the given
3618
Task<IEnumerable<Assembly>> GetRuntimeAssembliesAsync()
3719
```
3820

39-
For .Net 4.6+ (which isn't support in the latest version) returns `AppDomain.CurrentDomain.GetAssemblies();`. For .Net Core 2.0+ all the `DependencyContext.Default.GetRuntimeAssemblyNames(RuntimeEnvironment.GetRuntimeIdentifier())` assembly names are resolved.
21+
Returns a combination of `DependencyContext.Default.GetRuntimeAssemblyNames(Environment.OSVersion.Platform.ToString())` and `AppDomain.CurrentDomain.GetAssemblies()`.
4022

4123
``` c#
4224
Task<Type> GetTypeAsync(string typeName)
@@ -45,18 +27,12 @@ Task<Type> GetTypeAsync(string typeName)
4527
Attempts to find the requested type.
4628

4729
``` c#
48-
Task<IEnumerable<Type>> GetTypesAsync(Assembly assembly)
49-
```
50-
51-
Returns all types in the given `assembly`.
52-
53-
``` c#
54-
Task<IEnumerable<Type>> GetTypesAssignableToAsync(Type type, Assembly assembly)
30+
Task<IEnumerable<Type>> GetTypesCastableToAsync(Type type, Assembly assembly)
5531
// and these extensions
56-
Task<IEnumerable<Type>> GetTypesAssignableToAsync<T>();
57-
Task<IEnumerable<Type>> GetTypesAssignableToAsync(Type type);
58-
Task<IEnumerable<Type>> GetTypesAssignableToAsync<T>(Assembly assembly);
32+
Task<IEnumerable<Type>> GetTypesCastableToAsync<T>();
33+
Task<IEnumerable<Type>> GetTypesCastableToAsync(Type type);
34+
Task<IEnumerable<Type>> GetTypesCastableToAsync<T>(Assembly assembly);
5935
```
6036

61-
Returns all the types in the given `assembly` that are assignable to the `type` or `typeof(T)`; if no `assembly` is provided the all assemblies returned by `GetAssemblies()` will be scanned.
37+
Returns all the types in the given `assembly` that can be cast to the `type` or `typeof(T)`; if no `assembly` is provided the all assemblies returned by `GetAssembliesAsync()` will be scanned.
6238

Shuttle.Core.Reflection.Tests/EnumerableExtensionsFixture.cs

Lines changed: 29 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -3,41 +3,40 @@
33
using System.Linq;
44
using NUnit.Framework;
55

6-
namespace Shuttle.Core.Reflection.Tests
6+
namespace Shuttle.Core.Reflection.Tests;
7+
8+
[TestFixture]
9+
public class EnumerableExtensionsFixture
710
{
8-
[TestFixture]
9-
public class EnumerableExtensionsFixture
11+
private static IEnumerable<object> GetList()
1012
{
11-
private static IEnumerable<object> GetList()
13+
return new List<object>
1214
{
13-
return new List<object>
14-
{
15-
new SomeClass(),
16-
new SomeOtherClass(),
17-
new SomeOtherClass()
18-
};
19-
}
15+
new SomeClass(),
16+
new SomeOtherClass(),
17+
new SomeOtherClass()
18+
};
19+
}
2020

21-
[Test]
22-
public void Should_be_able_to_find_a_single_instance()
23-
{
24-
Assert.IsNotNull(GetList().Find<ISomeClass>());
25-
Assert.IsNull(GetList().Find<EnumerableExtensionsFixture>());
26-
}
21+
[Test]
22+
public void Should_be_able_to_find_a_single_instance()
23+
{
24+
Assert.That(GetList().Find<ISomeClass>(), Is.Not.Null);
25+
Assert.That(GetList().Find<EnumerableExtensionsFixture>(), Is.Null);
26+
}
2727

28-
[Test]
29-
public void Should_be_able_to_find_all_instances()
30-
{
31-
Assert.AreEqual(2, GetList().FindAll<ISomeOtherClass>().Count());
32-
Assert.AreEqual(1, GetList().FindAll<ISomeClass>().Count());
33-
Assert.AreEqual(0, GetList().FindAll<EnumerableExtensionsFixture>().Count());
34-
}
28+
[Test]
29+
public void Should_be_able_to_find_all_instances()
30+
{
31+
Assert.That(GetList().FindAll<ISomeOtherClass>().Count(), Is.EqualTo(2));
32+
Assert.That(GetList().FindAll<ISomeClass>().Count(), Is.EqualTo(1));
33+
Assert.That(GetList().FindAll<EnumerableExtensionsFixture>().Count(), Is.EqualTo(0));
34+
}
3535

36-
[Test]
37-
public void Should_be_able_to_get_a_single_instance()
38-
{
39-
Assert.IsNotNull(GetList().Get<ISomeClass>());
40-
Assert.Throws<InvalidOperationException>(() => GetList().Get<EnumerableExtensionsFixture>());
41-
}
36+
[Test]
37+
public void Should_be_able_to_get_a_single_instance()
38+
{
39+
Assert.That(GetList().Get<ISomeClass>(), Is.Not.Null);
40+
Assert.Throws<InvalidOperationException>(() => GetList().Get<EnumerableExtensionsFixture>());
4241
}
4342
}
Lines changed: 19 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,31 @@
11
using System;
22
using NUnit.Framework;
33

4-
namespace Shuttle.Core.Reflection.Tests
4+
namespace Shuttle.Core.Reflection.Tests;
5+
6+
[TestFixture]
7+
public class ExceptionExtensionsFixture
58
{
6-
[TestFixture]
7-
public class ExceptionExtensionsFixture
9+
[Test]
10+
public void Should_be_able_to_find_exception()
811
{
9-
[Test]
10-
public void Should_be_able_to_find_exception()
11-
{
12-
var ex = new Exception();
12+
var ex = new Exception();
1313

14-
Assert.That(ex.Find<Exception>(), Is.Not.Null);
15-
Assert.That(ex.Find<InvalidOperationException>(), Is.Null);
16-
Assert.That(ex.Contains<Exception>(), Is.True);
17-
Assert.That(ex.Contains<InvalidOperationException>(), Is.False);
14+
Assert.That(ex.Find<Exception>(), Is.Not.Null);
15+
Assert.That(ex.Find<InvalidOperationException>(), Is.Null);
16+
Assert.That(ex.Contains<Exception>(), Is.True);
17+
Assert.That(ex.Contains<InvalidOperationException>(), Is.False);
1818

19-
ex = new Exception(string.Empty, new InvalidOperationException());
19+
ex = new(string.Empty, new InvalidOperationException());
2020

21-
Assert.That(ex.Find<Exception>(), Is.Not.Null);
22-
Assert.That(ex.Find<InvalidOperationException>(), Is.Not.Null);
23-
Assert.That(ex.Contains<Exception>(), Is.True);
24-
Assert.That(ex.Contains<InvalidOperationException>(), Is.True);
21+
Assert.That(ex.Find<Exception>(), Is.Not.Null);
22+
Assert.That(ex.Find<InvalidOperationException>(), Is.Not.Null);
23+
Assert.That(ex.Contains<Exception>(), Is.True);
24+
Assert.That(ex.Contains<InvalidOperationException>(), Is.True);
2525

26-
ex = new Exception(string.Empty, new Exception(string.Empty, new InvalidOperationException()));
26+
ex = new(string.Empty, new(string.Empty, new InvalidOperationException()));
2727

28-
Assert.That(ex.Find<InvalidOperationException>(), Is.Not.Null);
29-
Assert.That(ex.Contains<InvalidOperationException>(), Is.True);
30-
}
28+
Assert.That(ex.Find<InvalidOperationException>(), Is.Not.Null);
29+
Assert.That(ex.Contains<InvalidOperationException>(), Is.True);
3130
}
3231
}
Lines changed: 21 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -1,63 +1,34 @@
1-
using System;
2-
using System.Linq;
3-
using System.Reflection;
1+
using System.Linq;
42
using System.Threading.Tasks;
53
using NUnit.Framework;
64

7-
namespace Shuttle.Core.Reflection.Tests
5+
namespace Shuttle.Core.Reflection.Tests;
6+
7+
[TestFixture]
8+
public class ReflectionServiceFixture
89
{
9-
[TestFixture]
10-
public class ReflectionServiceFixture
10+
[Test]
11+
public async Task Should_be_able_to_get_runtime_assemblies_async()
1112
{
12-
[Test]
13-
public void Should_be_able_to_get_runtime_assemblies()
14-
{
15-
Assert.That(new ReflectionService().GetRuntimeAssemblies().Count(), Is.GreaterThan(0));
16-
}
17-
18-
[Test]
19-
public async Task Should_be_able_to_get_runtime_assemblies_async()
20-
{
21-
Assert.That((await new ReflectionService().GetRuntimeAssembliesAsync()).Count(), Is.GreaterThan(0));
22-
}
23-
24-
[Test]
25-
public void Should_be_able_to_get_types()
26-
{
27-
Assert.That(new ReflectionService().GetTypesAssignableTo<SomeClass>().Count(), Is.EqualTo(1));
28-
Assert.That(new ReflectionService().GetTypesAssignableTo<ISomeClass>().Count(), Is.EqualTo(1));
29-
}
30-
31-
[Test]
32-
public async Task Should_be_able_to_get_types_async()
33-
{
34-
Assert.That((await new ReflectionService().GetTypesAssignableToAsync<SomeClass>()).Count(), Is.EqualTo(1));
35-
Assert.That((await new ReflectionService().GetTypesAssignableToAsync<ISomeClass>()).Count(), Is.EqualTo(1));
36-
}
13+
Assert.That((await new ReflectionService().GetRuntimeAssembliesAsync()).Count(), Is.GreaterThan(0));
14+
}
3715

38-
[Test]
39-
public void Should_be_able_to_get_matching_assemblies()
40-
{
41-
var service = new ReflectionService();
16+
[Test]
17+
public async Task Should_be_able_to_get_types_async()
18+
{
19+
Assert.That((await new ReflectionService().GetTypesCastableToAsync<SomeClass>()).Count(), Is.EqualTo(1));
20+
Assert.That((await new ReflectionService().GetTypesCastableToAsync<ISomeClass>()).Count(), Is.EqualTo(1));
21+
}
4222

43-
Assert.That(service.GetMatchingAssemblies(".+").Count(), Is.GreaterThan(0));
23+
public async Task Should_be_able_to_get_matching_assemblies_async()
24+
{
25+
var service = new ReflectionService();
4426

45-
foreach (var assembly in service.GetMatchingAssemblies("nunit"))
46-
{
47-
Assert.That(assembly.FullName.Contains("nunit"));
48-
}
49-
}
27+
Assert.That((await service.GetMatchingAssembliesAsync(".+")).Count(), Is.GreaterThan(0));
5028

51-
public async Task Should_be_able_to_get_matching_assemblies_async()
29+
foreach (var assembly in await service.GetMatchingAssembliesAsync("nunit"))
5230
{
53-
var service = new ReflectionService();
54-
55-
Assert.That((await service.GetMatchingAssembliesAsync(".+")).Count(), Is.GreaterThan(0));
56-
57-
foreach (var assembly in (await service.GetMatchingAssembliesAsync("nunit")))
58-
{
59-
Assert.That(assembly.FullName.Contains("nunit"));
60-
}
31+
Assert.That(assembly.FullName!.Contains("nunit"));
6132
}
6233
}
6334
}
Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,17 @@
11
<Project Sdk="Microsoft.NET.Sdk">
22

33
<PropertyGroup>
4-
<TargetFramework>net6.0</TargetFramework>
4+
<TargetFramework>net8.0</TargetFramework>
55
</PropertyGroup>
66

77
<ItemGroup>
8-
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.8.0" />
9-
<PackageReference Include="NUnit" Version="3.14.0" />
10-
<PackageReference Include="NUnit3TestAdapter" Version="4.5.0" />
8+
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.12.0" />
9+
<PackageReference Include="NUnit" Version="4.2.2" />
10+
<PackageReference Include="NUnit3TestAdapter" Version="4.6.0" />
1111
</ItemGroup>
1212

1313
<ItemGroup>
1414
<ProjectReference Include="..\Shuttle.Core.Reflection\Shuttle.Core.Reflection.csproj" />
1515
</ItemGroup>
1616

17-
</Project>
17+
</Project>
Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,9 @@
1-
namespace Shuttle.Core.Reflection.Tests
1+
namespace Shuttle.Core.Reflection.Tests;
2+
3+
public class SomeClass : ISomeClass
24
{
3-
public class SomeClass : ISomeClass
4-
{
5-
6-
}
5+
}
76

8-
public interface ISomeClass
9-
{
10-
}
7+
public interface ISomeClass
8+
{
119
}
Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,9 @@
1-
namespace Shuttle.Core.Reflection.Tests
1+
namespace Shuttle.Core.Reflection.Tests;
2+
3+
public class SomeOtherClass : ISomeOtherClass
24
{
3-
public class SomeOtherClass : ISomeOtherClass
4-
{
5-
6-
}
5+
}
76

8-
public interface ISomeOtherClass
9-
{
10-
}
7+
public interface ISomeOtherClass
8+
{
119
}

Shuttle.Core.Reflection/.package/AssemblyInfo.cs.template

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,7 @@
11
using System.Reflection;
22
using System.Runtime.InteropServices;
33

4-
#if NETFRAMEWORK
5-
[assembly: AssemblyTitle(".NET Framework")]
6-
#endif
7-
8-
#if NETCOREAPP
9-
[assembly: AssemblyTitle(".NET Core")]
10-
#endif
11-
12-
#if NETSTANDARD
13-
[assembly: AssemblyTitle(".NET Standard")]
14-
#endif
15-
4+
[assembly: AssemblyTitle(".NET Unified Platform")]
165
[assembly: AssemblyVersion("#{SemanticVersionCore}#.0")]
176
[assembly: AssemblyCopyright("Copyright (c) #{Year}#, Eben Roux")]
187
[assembly: AssemblyProduct("Shuttle.Core.Reflection")]

Shuttle.Core.Reflection/.package/Shuttle.NuGetPackager.targets

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
<?xml version="1.0" encoding="utf-8" ?>
1+
<?xml version="1.0" encoding="utf-8"?>
2+
23
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
34
<PropertyGroup>
45
<PackageTasksPath Condition="'$(PackageTasksPath)' == ''">Shuttle.NuGetPackager.MSBuild.dll</PackageTasksPath>
@@ -9,4 +10,4 @@
910
<UsingTask AssemblyFile="$(PackageTasksPath)" TaskName="Shuttle.NuGetPackager.MSBuild.NuGet.SetNuGetPackageVersions" />
1011
<UsingTask AssemblyFile="$(PackageTasksPath)" TaskName="Shuttle.NuGetPackager.MSBuild.Zip" />
1112
<UsingTask AssemblyFile="$(PackageTasksPath)" TaskName="Shuttle.NuGetPackager.MSBuild.NuGet.SemanticVersion" />
12-
</Project>
13+
</Project>

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
<package>
44
<metadata>
55
<id>Shuttle.Core.Reflection</id>
6-
<version>13.0.0</version>
6+
<version>20.0.0</version>
77
<authors>Eben Roux</authors>
88
<owners>Eben Roux</owners>
99
<license type="expression">BSD-3-Clause</license>
@@ -13,11 +13,11 @@
1313
<repository type="git" url="https://github.com/shuttle/Shuttle.Core.Reflection.git" />
1414
<projectUrl>https://github.com/shuttle/Shuttle.Core.Reflection</projectUrl>
1515
<description>Reflection infrastructure components.</description>
16-
<copyright>Copyright (c) 2024, Eben Roux</copyright>
16+
<copyright>Copyright (c) 2025, Eben Roux</copyright>
1717
<tags>shuttle reflection</tags>
1818
<dependencies>
19-
<dependency id="Microsoft.Extensions.DependencyModel" version="7.0.0" />
20-
<dependency id="Shuttle.Core.Contract" version="11.1.0" />
19+
<dependency id="Microsoft.Extensions.DependencyModel" version="8.0.2" />
20+
<dependency id="Shuttle.Core.Contract" version="20.0.0" />
2121
</dependencies>
2222
</metadata>
2323
<files>

0 commit comments

Comments
 (0)