Ecosyste.ms: Awesome

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

Awesome Lists | Featured Topics | Projects

https://github.com/ignatandrei/RSCG_WhatIAmDoing

Instrument C# software on CI to find what the software is doing
https://github.com/ignatandrei/RSCG_WhatIAmDoing

Last synced: about 1 month ago
JSON representation

Instrument C# software on CI to find what the software is doing

Awesome Lists containing this project

README

        

# RSCG_WhatIAmDoing

Instrument C# software on CI to find what the software is doing.

# Introduction

Decide what you want to monitor ... and then monitor it.

# Example

## Packages

Add the following into the csproj you want to be monitores

```xml




true
$(BaseIntermediateOutputPath)\GX
$(InterceptorsPreviewNamespaces);RSCG_InterceptorTemplate

```

## Code

### Intercept static methods
Assume that you want to monitor all calls to System.Console

```csharp
//[ExposeClass(typeof(Encoding), nameof(Encoding.EncodingName))]
//[InterceptStatic("System.IO.File.*ts")]
//[InterceptStatic("System.IO.File.*")]
[InterceptStatic("System.Console.*")] // regex
//[InterceptStatic("WIAD_DemoConsole.Fib.*")]
internal class InterceptorMethodStatic : InterceptorMethodStaticBase, IInterceptorMethodStatic
{

}
```

### Intercept instance methods

Assume that you want to monitor all calls to any method of any instance of Person

```csharp
//[InterceptInstanceClass(typeof(Person),"ame")]
//[InterceptInstanceClass(typeof(Person), "parat")]
//[InterceptInstanceClass(typeof(Person), "ncodi")]
[InterceptInstanceClass(typeof(Person), ".*")] //regex
public class InterceptorMethodInstanceClass: InterceptorMethodInstanceClassBase, IInterceptorMethodInstanceClass
{

public InterceptorMethodInstanceClass()
{

}

}
```

### See the results

```csharp
var data= CachingData.Methods().ToArray();

foreach (var item in data)
{
WriteLine($"Method {item.typeAndMethodData.MethodName} from class {item.typeAndMethodData.TypeOfClass} Time: {item.StartedAtDate} state {item.State} ");
WriteLine($" =>Arguments: {item.ArgumentsAsString()}");
if ((item.State & AccumulatedStateMethod.HasResult) == AccumulatedStateMethod.HasResult)
{
WriteLine($" =>Result: {item.Result}");
}

}

```

# More details

If you want to implement YOUR interception , implement the following interfaces

IInterceptorMethodInstanceClass

IInterceptorMethodStatic

# License

MIT