OutWit.Common.Proxy.Generator
2.0.8
See the version list below for details.
dotnet add package OutWit.Common.Proxy.Generator --version 2.0.8
NuGet\Install-Package OutWit.Common.Proxy.Generator -Version 2.0.8
<PackageReference Include="OutWit.Common.Proxy.Generator" Version="2.0.8" />
<PackageVersion Include="OutWit.Common.Proxy.Generator" Version="2.0.8" />
<PackageReference Include="OutWit.Common.Proxy.Generator" />
paket add OutWit.Common.Proxy.Generator --version 2.0.8
#r "nuget: OutWit.Common.Proxy.Generator, 2.0.8"
#:package OutWit.Common.Proxy.Generator@2.0.8
#addin nuget:?package=OutWit.Common.Proxy.Generator&version=2.0.8
#tool nuget:?package=OutWit.Common.Proxy.Generator&version=2.0.8
OutWit.Common.Proxy.Generator
OutWit.Common.Proxy.Generator is a source generator that automatically creates proxy classes for interfaces marked with the ProxyTargetAttribute from the OutWit.Common.Proxy library.
Features
- Automatically generates proxies for interfaces with events, methods, and properties.
- Integrates seamlessly with custom
IProxyInterceptorimplementations.
Getting Started
Installation
Add OutWit.Common.Proxy.Generator to your project via NuGet:
dotnet add package OutWit.Common.Proxy.Generator
Usage
Ensure your interface is marked with the
ProxyTargetAttribute:using OutWit.Common.Proxy; [ProxyTarget] public interface IExampleService { string GetData(int id); event EventHandler DataChanged; }Implement
IProxyInterceptorto handle invocations:public class ExampleInterceptor : IProxyInterceptor { public void Intercept(IProxyInvocation invocation) { Console.WriteLine($"Intercepted method: {invocation.MethodName}"); if (invocation.MethodName == "GetData") { invocation.ReturnValue = $"Data for ID {invocation.Parameters[0]}"; } } }Use the generated proxy in your code:
var interceptor = new ExampleInterceptor(); var proxy = new ExampleServiceProxy(interceptor); var result = proxy.GetData(42); Console.WriteLine(result); // Output: Data for ID 42
Support for Methods, Properties, and Events
Methods
When a method is called, a ProxyInvocation object is created and passed to the Intercept method. The return value of the method is taken from invocation.ReturnValue.
Properties
OutWit.Common.Proxy.Generator supports both getters and setters for properties. Each invocation is wrapped in a ProxyInvocation object, similar to methods.
Events
The generator handles subscription (add) and unsubscription (remove) for events, passing the relevant details to the Intercept method.
License
Licensed under the Apache License, Version 2.0. See LICENSE.
Attribution (optional)
If you use OutWit.Common.Proxy.Generator in a product, a mention is appreciated (but not required), for example: "Powered by OutWit.Common.Proxy.Generator (https://ratner.io/)".
Trademark / Project name
"OutWit" and the OutWit logo are used to identify the official project by Dmitry Ratner.
You may:
- refer to the project name in a factual way (e.g., "built with OutWit.Common.Proxy.Generator");
- use the name to indicate compatibility (e.g., "OutWit.Common.Proxy.Generator-compatible").
You may not:
- use "OutWit.Common.Proxy.Generator" as the name of a fork or a derived product in a way that implies it is the official project;
- use the OutWit.Common.Proxy.Generator logo to promote forks or derived products without permission.
Learn more about Target Frameworks and .NET Standard.
-
.NETStandard 2.0
- OutWit.Common.Proxy (>= 1.2.8)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.