SWZR.Dynamxy
0.1.0
dotnet add package SWZR.Dynamxy --version 0.1.0
NuGet\Install-Package SWZR.Dynamxy -Version 0.1.0
<PackageReference Include="SWZR.Dynamxy" Version="0.1.0" />
paket add SWZR.Dynamxy --version 0.1.0
#r "nuget: SWZR.Dynamxy, 0.1.0"
// Install SWZR.Dynamxy as a Cake Addin #addin nuget:?package=SWZR.Dynamxy&version=0.1.0 // Install SWZR.Dynamxy as a Cake Tool #tool nuget:?package=SWZR.Dynamxy&version=0.1.0
Dynamxy
Library for .NET enabling the use of dynamic proxy objects.
Getting Started
Either fork, clone or download this repository. Or install the library via NuGet:
Install-Package SWZR.Dynamxy
How does it work
During instantiation of a proxy object, code is dynamically emitted using primarly IL to create a concrete implementation based on a given interface. This type functions as intermediary and forwards any method call to the predefined interceptor.
Usage
In order to use dynamic proxy objects first define an interface:
public interface ITestInterface
{
object Echo(object obj);
}
Afterwards define an interceptor which handles all method calls:
using System.Reflection;
using SWZR.Dynamxy;
public class EchoInterceptor : IInterceptor
{
public object InterceptMethod(object instance, MethodInfo info, object[] parameter)
{
return parameter.Length > 0 ? parameter[0] : null;
}
}
The last step is to construct an instance of the interceptor and eventually the dynamic proxy itself:
var factory = new ProxyFactory<EchoInterceptor>();
var proxy = factory.Create<ITestInterface>();
// Will yield 'Hello World'.
var value = proxy.Echo("Hello World");
Use Cases
- Authorization
- Logging
- REST
- RPC
- ...
Roadmap
- Improve and extend unit tests
- Allow intercepting methods of concrete types
- Add an example
License
This project is licensed under the MIT License - see the LICENSE.md file for details
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET Framework | net471 is compatible. net472 was computed. net48 was computed. net481 was computed. |
This package has no dependencies.
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.
Version | Downloads | Last updated |
---|---|---|
0.1.0 | 917 | 3/15/2018 |