Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/puresharper/cneptune
CNeptune improve productivity & efficiency by urbanize .net module with meta-code to lay foundation for frameworks
https://github.com/puresharper/cneptune
aop architecture aspect-oriented-programming cil container cross-cutting-concerns dependency design di efficiency injection interception inversion-of-control ioc mock mocking pattern productivity
Last synced: 2 months ago
JSON representation
CNeptune improve productivity & efficiency by urbanize .net module with meta-code to lay foundation for frameworks
- Host: GitHub
- URL: https://github.com/puresharper/cneptune
- Owner: Puresharper
- License: mit
- Created: 2017-01-12T12:04:17.000Z (about 8 years ago)
- Default Branch: master
- Last Pushed: 2018-04-26T20:46:19.000Z (over 6 years ago)
- Last Synced: 2024-11-12T12:52:52.183Z (2 months ago)
- Topics: aop, architecture, aspect-oriented-programming, cil, container, cross-cutting-concerns, dependency, design, di, efficiency, injection, interception, inversion-of-control, ioc, mock, mocking, pattern, productivity
- Language: C#
- Homepage:
- Size: 54.7 KB
- Stars: 31
- Watchers: 5
- Forks: 7
- Open Issues: 12
-
Metadata Files:
- Readme: README.md
- License: LICENSE.md
Awesome Lists containing this project
README
[![NuGet](https://img.shields.io/nuget/v/cneptune.svg)](https://www.nuget.org/packages/CNeptune)
# CNeptuneCNeptune is an util based on mono.cecil to rewrite .net assembly to inject all the needs to control execution flow in order to help architects to build a productive and efficient architecture.
## Features
- Dynamic : change method behavior at runtime
- Efficient : injected mechanism is extremely efficient
- Limitless : support all type of methods (constructors included)
- Transparent : client side perception is not affected## Coverage
- Aspect-Oriented Programming
- Code contract / Data validation
- Uncoupling technical concern
- Diagnostics & measures
- Mocking & tests
- Simplify existing design pattern## Example of injection
- Rewrite .net assembly by specifying path
```
neptune.exe "C:\...\Assembly.dll"
```
- Rewrite .net assembly by specifying project and configuration
```
neptune.exe "C:\...\Project.csproj" "Debug"
```
- Rewrite is automatically done after build and before link by adding CNeptune nuget package : https://www.nuget.org/packages/CNeptune
```
PM> Install-Package CNeptune
```## Example of usage
- Override method at runtimeBusiness
```
public class Calculator
{
public int Add(int a, int b)
{
return a + b;
}
}
```Obtain the delegate to manage a method of 'Calculator'
```
var _update = typeof(Calculator).GetNestedType("", BindingFlags.NonPublic).GetField("").GetValue(null) as Action>;
```Define 'Add' method to inject a console 'Hello World' before call.
```
_update
(
typeof(Calculator).GetMethod("Add"),
_Method =>
{
var _method = new DynamicMethod(string.Empty, typeof(int), new Type[] { typeof(Calculator), typeof(int), typeof(int) }, typeof(Calculator), true);
var _body = _method.GetILGenerator();
_body.EmitWriteLine("Hello World");
_body.Emit(OpCodes.Ldarg_0); //this
_body.Emit(OpCodes.Ldarg_1); //a
_body.Emit(OpCodes.Ldarg_2); //b
_body.Emit(OpCodes.Call, _Method);
_body.Emit(OpCodes.Ret);
return _method;
}
);
```