IFY.Shimr
2.1.4
dotnet add package IFY.Shimr --version 2.1.4
NuGet\Install-Package IFY.Shimr -Version 2.1.4
<PackageReference Include="IFY.Shimr" Version="2.1.4" />
<PackageVersion Include="IFY.Shimr" Version="2.1.4" />
<PackageReference Include="IFY.Shimr" />
paket add IFY.Shimr --version 2.1.4
#r "nuget: IFY.Shimr, 2.1.4"
#:package IFY.Shimr@2.1.4
#addin nuget:?package=IFY.Shimr&version=2.1.4
#tool nuget:?package=IFY.Shimr&version=2.1.4
<div align="center">

</div>
Shimr
Utility for creating a dynamic object facade/proxy to allow for using an object as an interface that it does not explicitly implement.
Formerly known as Shimterface:
Description
I'm sure we've all been in the situation where we've had to make use of a class from an external library (including mscorlib) that either doesn't implement any interface or doesn't implement one that can be used for any kind of Inversion of Control usage. One approach is to implement a series of proxy objects that handle all of the required functionality, including proxies around returned values, and this can even be scripted (Powershell, T4, etc.) to prevent the arduous task of proxying every class you need.
You might also be frustrated that classes can't have an identical interface applied to them post-design. e.g.,
public class TestClass {
public void Test() {
...
}
}
public interface ITest {
void Test();
}
ITest forcedCast = (ITest)new TestClass();
Given that TestClass implements all of ITest members, logically this would be a lovely language feature. Instead, we get a runtime InvalidCastException.
Shimr solves and takes the effort out of this problem by compiling dynamic proxies to convert classes to the requested interface. The above example can be fixed using Shimr by doing:
ITest forcedCast = new TestClass().Shim<ITest>();
If you ever needed the original back again, then you simply unshim it:
TestClass originalObject = ShimBuilder.Unshim<TestClass>(forcedCast);
The wiki contains lots more examples and detailed coverage of usage.
Breaking changes
See the breaking change wiki.
Design principal
The purpose of Shimr is to improve testability and inversion-of-control; therefore, all behavioural decisions are designed to be implemented as application design-time. This is not a mocking library.
Outside of setting up your DI/IOC container and facades, if you're referencing Shimr directly, it's likely that you're thinking about a different problem domain to the one solved by this library.
Known Issues
- If the compilation of the proxy type fails but the application handles it, the Type-Interface combination is now not usable
Future Ideas
- Generate assembly of compiled shims for direct reference
- Combine multiple target types to single shim
- Behavioural configuration to attributes (e.g., [Shim(IgnoreMissingMembers = true)])
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net5.0 was computed. net5.0-windows was computed. net6.0 was computed. net6.0-android was computed. net6.0-ios was computed. net6.0-maccatalyst was computed. net6.0-macos was computed. net6.0-tvos was computed. net6.0-windows was computed. net7.0 was computed. net7.0-android was computed. net7.0-ios was computed. net7.0-maccatalyst was computed. net7.0-macos was computed. net7.0-tvos was computed. net7.0-windows was computed. net8.0 was computed. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. net9.0 was computed. net9.0-android was computed. net9.0-browser was computed. net9.0-ios was computed. net9.0-maccatalyst was computed. net9.0-macos was computed. net9.0-tvos was computed. net9.0-windows was computed. net10.0 was computed. net10.0-android was computed. net10.0-browser was computed. net10.0-ios was computed. net10.0-maccatalyst was computed. net10.0-macos was computed. net10.0-tvos was computed. net10.0-windows was computed. |
| .NET Core | netcoreapp3.0 was computed. netcoreapp3.1 was computed. |
| .NET Standard | netstandard2.1 is compatible. |
| MonoAndroid | monoandroid was computed. |
| MonoMac | monomac was computed. |
| MonoTouch | monotouch was computed. |
| Tizen | tizen60 was computed. |
| Xamarin.iOS | xamarinios was computed. |
| Xamarin.Mac | xamarinmac was computed. |
| Xamarin.TVOS | xamarintvos was computed. |
| Xamarin.WatchOS | xamarinwatchos was computed. |
-
.NETStandard 2.1
- System.Reflection.Emit (>= 4.7.0)
NuGet packages (1)
Showing the top 1 NuGet packages that depend on IFY.Shimr:
| Package | Downloads |
|---|---|
|
IFY.Phorm.Core
The core "Procedure-heavy object-relational mapping" framework. Intended to be implemented by a provider-specific package. |
GitHub repositories
This package is not used by any popular GitHub repositories.
[v2.1.4] Static shims support implemented interface members
[v2.1.3] Improved handling of hidden members
[v2.1.2] More deterministic handling of conflicting methods
[v2.1.1] Improved performance of task shimming
[v2.1.0] Support for Task<> and ValueTask<> shimming