Clover. Proxy is a Class Library Based on. NET 4.0,
Project address: https://github.com/xwj90/Clover.Proxy (MIT, whatever you want)
It provides a simple way to execute the methods and attributes in the existing class library by proxy. It can be used in the following situations:
1. Add beforecall and aftercall to the methods and attributes of the existing class.
- By assigning delegate values, you can easily customize beforecall and aftercall.
- In beforecall and aftercall, you can perform log recording, analyze parameters, modify parameters, and record the number of calls to each method. (You can enable or disable the function through configuration to facilitate debugging)
- Through configuration, you can easily control the impact scope.
- Automatically Generated by modifyingCode, You can do more, such as automatically adding logs to some methods and modifying variables during execution.
2. the proxy supports migrating existing methods to different AppDomains for execution (the main function is completed)
- Control the performance and resource consumption of independent appdomain
- Cross-appdomain operations are highly independent and can be extended to automatic update and restart (in Plug-in form that requires development)
- Because each appdomain supports its own configuration file, we can modify the behavior of many existing class libraries by configuring different configuration files for different classes and assemblies.
- For example, if a log system is used for an existing project, the logs of the entire project must be written to a file. Different configuration files allow different classes or differentProgramSet to write different log files
- Cross-origin performance loss
3. This project is more like a research project that involves the following technologies: (if you are interested, look at the source code)
- Dynamic generation of CS files and compilation into assembly
- Analyze type-related information
- Knowledge about class inheritance
- Dynamically create appdomain and load assembly
- Cross-origin operations
The following is a sample:
Proxyservice service = New Proxyservice ();
Service. beforecall = (p) =>
{
Console. writeline ( " Before call: " + P. Arguments );
};
Service. aftercall = (p) =>
{
Console. writeline ( " After call: " + P. returnvalue );
};
VaR Item = service. Create <testwrapper> ();
// Method
VaR R1 = item. getall ( 128 , " Test string " );
Console. writeline ();
// Property can be set by configuring a method, or some methods need to call beforecall & aftercall
VaR R2 = item. Name;
Console. writeline ();
VaR Item2 = service. Create <testwrapper2> ();
VaR R3 = item2.test ( " Test string " );// Run method in remote domain // Incomplete
Thanks to shiweichuan and weikaishio