Splice 0.0.1-rc2
See the version list below for details.
dotnet add package Splice --version 0.0.1-rc2
NuGet\Install-Package Splice -Version 0.0.1-rc2
<PackageReference Include="Splice" Version="0.0.1-rc2"> <PrivateAssets>all</PrivateAssets> <IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets> </PackageReference>
<PackageVersion Include="Splice" Version="0.0.1-rc2" />
<PackageReference Include="Splice"> <PrivateAssets>all</PrivateAssets> <IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets> </PackageReference>
paket add Splice --version 0.0.1-rc2
#r "nuget: Splice, 0.0.1-rc2"
#:package Splice@0.0.1-rc2
#addin nuget:?package=Splice&version=0.0.1-rc2&prerelease
#tool nuget:?package=Splice&version=0.0.1-rc2&prerelease
Splice 🚀
A C# .NET solution focused on Roslyn Source Generators, specifically implementing C# 14 "Interceptors". This framework allows you to easily intercept and replace method calls at compile time.
Quick Start 🏁
1. Installation 📦
Add the Splice as a source generator to your project. If you are using NuGet:
dotnet add package Splice
2. Project Configuration ⚙️
Interceptors are a C# 11+ feature (fully matured in C# 14). You need to enable them in your .csproj (C# 12+ required for basic support, C# 14 for full stability):
<PropertyGroup>
<LangVersion>preview</LangVersion>
<InterceptorsNamespaces>$(InterceptorsNamespaces);MyProject.Interceptors</InterceptorsNamespaces>
<EmitCompilerGeneratedFiles>true</EmitCompilerGeneratedFiles>
</PropertyGroup>
How to Use 🛠️
Create an Interceptor
To intercept a method, create a partial class and a partial method decorated with the [Interceptor] attribute.
using System;
using Generators; // Namespace for the [Interceptor] attribute
namespace MyProject.Interceptors;
public static partial class MyInterceptor
{
// Intercept Console.WriteLine(string) calls
[Interceptor(typeof(Console), nameof(Console.WriteLine))]
public static partial void WriteLine(string? message)
{
// NOTE: Calls to the intercepted method within its OWN body are NOT intercepted.
// However, if this method calls ANOTHER method that then calls Console.WriteLine,
// ⚠️ you might run into infinite recursion!
Console.WriteLine($"[Intercepted] {message}");
}
}
Attribute Variations
The framework provides two ways to specify the target method:
<details> <summary><b>1. Type-based (Recommended for non-generic targets)</b></summary>
[Interceptor(typeof(TargetType), "MethodName")]
</details>
<details> <summary><b>2. Generic-based (Clean syntax)</b></summary>
[Interceptor<TargetType>("MethodName")]
</details>
Configuration Details ⚙️
The InterceptorsNamespaces Property
The C# compiler requires you to explicitly list the namespaces that are allowed to contain interceptors for security and performance reasons.
If your interceptor is in MyProject.Interceptors, you must add that namespace to the <InterceptorsNamespaces> property in your .csproj. You can add multiple namespaces separated by semicolons.
<InterceptorsNamespaces>$(InterceptorsNamespaces);Namespace1;Namespace2</InterceptorsNamespaces>
Features ✨
- Core Interceptor Source Generator: Automatically maps interceptors to their call sites.
- Recursion Protection: Prevents an interceptor from intercepting itself (only within its own method body).
- Sample project: Real-world demonstration of interception.
- Comprehensive test suite: Using xUnit v3 to ensure stability.
Automated Workflows 🤖
Continuous Integration (CI)
The project uses GitHub Actions to automatically build and test every push and pull request targeting the main branch.
Continuous Deployment (CD)
Releases are automated via GitHub Actions. Pushing a tag matching v* (e.g., v1.0.0) triggers:
- Automated build and test.
- Creation of a GitHub Release with build artifacts.
- Publishing the package to NuGet.org.
Note: To publish to NuGet, a NUGET_API_KEY must be configured in the repository's GitHub Secrets.
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net5.0 was computed. net5.0-windows was computed. net6.0 was computed. net6.0-android was computed. net6.0-ios was computed. net6.0-maccatalyst was computed. net6.0-macos was computed. net6.0-tvos was computed. net6.0-windows was computed. net7.0 was computed. net7.0-android was computed. net7.0-ios was computed. net7.0-maccatalyst was computed. net7.0-macos was computed. net7.0-tvos was computed. net7.0-windows was computed. net8.0 was computed. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. net9.0 was computed. net9.0-android was computed. net9.0-browser was computed. net9.0-ios was computed. net9.0-maccatalyst was computed. net9.0-macos was computed. net9.0-tvos was computed. net9.0-windows was computed. net10.0 was computed. net10.0-android was computed. net10.0-browser was computed. net10.0-ios was computed. net10.0-maccatalyst was computed. net10.0-macos was computed. net10.0-tvos was computed. net10.0-windows was computed. |
| .NET Core | netcoreapp2.0 was computed. netcoreapp2.1 was computed. netcoreapp2.2 was computed. netcoreapp3.0 was computed. netcoreapp3.1 was computed. |
| .NET Standard | netstandard2.0 is compatible. netstandard2.1 was computed. |
| .NET Framework | net461 was computed. net462 was computed. net463 was computed. net47 was computed. net471 was computed. net472 was computed. net48 was computed. net481 was computed. |
| MonoAndroid | monoandroid was computed. |
| MonoMac | monomac was computed. |
| MonoTouch | monotouch was computed. |
| Tizen | tizen40 was computed. tizen60 was computed. |
| Xamarin.iOS | xamarinios was computed. |
| Xamarin.Mac | xamarinmac was computed. |
| Xamarin.TVOS | xamarintvos was computed. |
| Xamarin.WatchOS | xamarinwatchos was computed. |
-
.NETStandard 2.0
- Microsoft.CodeAnalysis.CSharp (>= 5.0.0)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.