Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/robertturner/StaticProxyGenerator
https://github.com/robertturner/StaticProxyGenerator
Last synced: about 1 month ago
JSON representation
- Host: GitHub
- URL: https://github.com/robertturner/StaticProxyGenerator
- Owner: robertturner
- License: mit
- Created: 2020-09-01T09:03:10.000Z (over 4 years ago)
- Default Branch: master
- Last Pushed: 2020-12-13T07:38:28.000Z (almost 4 years ago)
- Last Synced: 2024-11-01T05:46:14.223Z (about 1 month ago)
- Language: C#
- Size: 21.5 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
- RSCG_Examples - StaticProxyGenerator
README
# StaticProxyGenerator
Interface proxy generator.
At compile time creates class that implements target interface. Instantiation of the generated class accepts an InterceptorHandler which is called for all method calls.## Example
```
public interface IMyIfce
{
Task AsyncMethod(string arg1);
Task MethodWithNoReturn(int arg1, string arg2);
void SyncMethodNoArgs();
}
```
Create proxy of interface:
```
object interceptionHandler(object instance, MethodInfo method, object[] args, Type[] genericArguments)
{
switch (method.Name)
{
case nameof(IMyIfce.AsyncMethod):
return Task.FromResult((string)args[0]);
...
}
}// Get instance of proxy
IMyIfce ifceProxy = ProxyGeneratorHelpers.InstantiateProxy(interceptionHandler);
```
Super happy place:
```
string result = await ifceProxy.AsyncMethod("an arg");
...
await ifceProxy.MethodWithNoReturn(4, "arg2");
...
ifceProxy.SyncMethodNoArgs();
```