Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/ignatandrei/rscg_decorator

Decorator for classes , permit to know when method start and ends
https://github.com/ignatandrei/rscg_decorator

Last synced: 5 days ago
JSON representation

Decorator for classes , permit to know when method start and ends

Awesome Lists containing this project

README

        

# RSCG_Decorator
Decorator for classes , permit to know when method start and ends

## Usage

Add reference to RSCG_Decorator and RSCG_DecoratorCommon

```xml



true
$(BaseIntermediateOutputPath)\GX


```

For any class that you want to intercept methods, implement interface IDecoratorMethodV1

See example at the RSCG_DecoratorTestConsole

```csharp
public partial class Person : IDecoratorMethodV1
{
public void EndMethod(MethodRecognizer recognizer)
{
logger.LogInformation("end "+recognizer.UniqueId);
}


public void ExceptionMethod(Exception ex, MethodRecognizer recognizer)
{
logger.LogError(ex, "exception on " + recognizer.UniqueId+ " Value Parameters:" + recognizer.ValueTypeParametersString);
}

public void StartMethod(MethodRecognizer recognizer)
{
logger.LogInformation("start " + recognizer.UniqueId + " Value Parameters:"+recognizer.ValueTypeParametersString);
}
}
```

## Usage with ASP.NET Core - or any DI framework

Let's take Person with interface IPerson. You have the following:

```csharp
serviceCollection
.AddTransient();

```
You can add this as the latest

```csharp
serviceCollection = serviceCollection
.AddTransient()
.AddTransient();

```

And when asking for IPerson , the last wins:

```csharp

var data = serviceProvider.GetRequiredService();
//obtaining Person_Decorator because is the last one

```
# More Roslyn Source Code Generators

You can find more RSCG with examples at [Roslyn Source Code Generators](https://ignatandrei.github.io/RSCG_Examples/v2/)