{"id":23170976,"url":"https://github.com/ignatandrei/rscg_interceptortemplate","last_synced_at":"2026-03-09T04:03:57.238Z","repository":{"id":208883062,"uuid":"722707232","full_name":"ignatandrei/RSCG_InterceptorTemplate","owner":"ignatandrei","description":"Interceptor templating","archived":false,"fork":false,"pushed_at":"2024-09-03T22:34:28.000Z","size":90,"stargazers_count":1,"open_issues_count":1,"forks_count":0,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-09-15T23:44:02.452Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"C#","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/ignatandrei.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2023-11-23T18:47:10.000Z","updated_at":"2024-01-12T09:02:35.000Z","dependencies_parsed_at":"2023-11-23T20:21:09.720Z","dependency_job_id":"e0963f8f-86f0-4650-bf0b-0bbf7536134a","html_url":"https://github.com/ignatandrei/RSCG_InterceptorTemplate","commit_stats":null,"previous_names":["ignatandrei/rscg_interceptortemplate"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/ignatandrei/RSCG_InterceptorTemplate","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ignatandrei%2FRSCG_InterceptorTemplate","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ignatandrei%2FRSCG_InterceptorTemplate/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ignatandrei%2FRSCG_InterceptorTemplate/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ignatandrei%2FRSCG_InterceptorTemplate/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ignatandrei","download_url":"https://codeload.github.com/ignatandrei/RSCG_InterceptorTemplate/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ignatandrei%2FRSCG_InterceptorTemplate/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":30282557,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-03-09T02:57:19.223Z","status":"ssl_error","status_checked_at":"2026-03-09T02:56:26.373Z","response_time":61,"last_error":"SSL_read: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-12-18T04:15:45.632Z","updated_at":"2026-03-09T04:03:54.599Z","avatar_url":"https://github.com/ignatandrei.png","language":"C#","funding_links":[],"categories":[],"sub_categories":[],"readme":"# RSCG_InterceptorTemplate\n\nInterceptor template - supported from \u003e= .NET 8.0 . Uses also experimental interceptor feature from C#12.0\n\nIt can rewrite any method call to any other method call. It can also rewrite any method call to any other method call with the same signature. It can also rewrite any method call to any other method call with the same signature and the same return type.\n\nIt does not ( yet ) support generic methods.\n\nFor example, if you have a method call like this:\n\n```csharp\nConsole.WriteLine(\"and now with argument \" + newPerson.TestFullNameWithArguments(\"\u003c\",\"!+\",\"\u003e\",2));\n```\n\nit can intercept it with the arguments .\n\nFor example, if you use this template \n\n```csharp\npublic static {{(ser.item.HasTaskReturnType?\"async\":\"\")}} {{ser.item.TypeReturn}} {{ser.item.MethodSignature}}({{ser.item.ThisArgument}} {{ser.item.ArgumentsForCallMethod}} )  \n{\n    var cc=Console.BackgroundColor ;\n    try{\n        Console.BackgroundColor = ConsoleColor.DarkRed;\n        Console.WriteLine(\"start specific TestFullNameWithArguments template--\u003e{{ser.item.MethodSignature}}\");\n        Console.WriteLine(\"number of arguments = {{ser.item.Arguments.size}}\");\n        {{ for argum in ser.item.Arguments }}\n        Console.WriteLine(\"argument {{for.index+1}} type {{argum.Type}} and value = \"+ {{argum.Name}});\n        {{ end }}\n        {{ser.item.ReturnString}} {{(ser.item.HasTaskReturnType ? \"await\" : \"\")}} {{ser.item.CallMethod}};\n    }\n    finally{\n        Console.WriteLine(\"end specific template--\u003e{{ser.item.MethodSignature}}\");\n        Console.BackgroundColor = cc;\n    }\n}\n```\n\nThe final result will be:\n\n```csharp\npublic static  string Intercept_newPerson_TestFullNameWithArguments(this RSCG_DemoObjects.Person newPerson ,string start,string separator,string end,int repeat )  \n{\n    var cc=Console.BackgroundColor ;\n    try{\n        Console.BackgroundColor = ConsoleColor.DarkRed;\n        Console.WriteLine(\"start specific TestFullNameWithArguments template--\u003eIntercept_newPerson_TestFullNameWithArguments\");\n        Console.WriteLine(\"number of arguments = 4\");\n        Console.WriteLine(\"argument 1 type string and value = \"+ start);\n        Console.WriteLine(\"argument 2 type string and value = \"+ separator);\n        Console.WriteLine(\"argument 3 type string and value = \"+ end);\n        Console.WriteLine(\"argument 4 type int and value = \"+ repeat);\n        return  newPerson.TestFullNameWithArguments(start,separator,end,repeat);\n    }\n    finally{\n        Console.WriteLine(\"end specific template--\u003eIntercept_newPerson_TestFullNameWithArguments\");\n        Console.BackgroundColor = cc;\n    }\n}\n```\n\nYou can use any template . Some examples at src/RSCG_InterceptorTemplateConsole/Interceptors\n\n\n## How to use it\n\n\nAdd to your project (\u003e= .NET 8 ) the nuget package RSCG_InterceptorTemplate\n\n```xml\n\u003cItemGroup\u003e\n \u003cPackageReference Include=\"RSCG_InterceptorTemplate\" Version=\"8.2023.2811.524\" OutputItemType=\"Analyzer\" ReferenceOutputAssembly=\"false\" /\u003e\n\u003c/ItemGroup\u003e\n\u003cPropertyGroup\u003e\n    \u003cEmitCompilerGeneratedFiles\u003etrue\u003c/EmitCompilerGeneratedFiles\u003e\n    \u003cCompilerGeneratedFilesOutputPath\u003e$(BaseIntermediateOutputPath)\\GX\u003c/CompilerGeneratedFilesOutputPath\u003e\n    \u003cInterceptorsPreviewNamespaces\u003e$(InterceptorsPreviewNamespaces);RSCG_InterceptorTemplate\u003c/InterceptorsPreviewNamespaces\u003e\n\u003c/PropertyGroup\u003e\n```\n\nMake a folder Interceptors in the project and add also at least the generic interceptor ( see templates at src/RSCG_InterceptorTemplateConsole/Interceptors/ , start with GenericInterceptorForAllMethods.txt )\n\n```csharp\n\n```xml\n  \u003cItemGroup\u003e\n    \u003c!-- \u003cAdditionalFiles Include=\"Interceptors\\TestFullNameWithArguments.txt\"\u003e\n      \u003cCopyToOutputDirectory\u003ePreserveNewest\u003c/CopyToOutputDirectory\u003e\n    \u003c/AdditionalFiles\u003e --\u003e\n    \u003cAdditionalFiles Include=\"Interceptors\\GenericInterceptorForAllMethods.txt\"\u003e\n      \u003cCopyToOutputDirectory\u003ePreserveNewest\u003c/CopyToOutputDirectory\u003e\n    \u003c/AdditionalFiles\u003e\n  \u003c/ItemGroup\u003e\n```\n\nThe interceptor will not run template at build time in Visual Studiom, but it will run at build time in dotnet build.\n\nFor this, you need to have something like that ( powershell file) -I named mine compile.ps1\n\n```powershell\ncls\n#not necessary for CI builds, but only for debugging purposes\nWrite-Host \"delete obj and bin\"\ngci obj -recurse | foreach{ri $_.FullName -recurse -force }\ngci bin -recurse | foreach{ri $_.FullName -recurse -force }\n#for windows batch file \n#setx InterceptMethods \"FullName\"\n#echo Environment variable InterceptMethods has been set to %InterceptMethods%\n#put here the names of the methods you want to intercept , separated by ;\n$env:InterceptMethods = \"FullName;Test;PersonsLoaded;TestFullNameWithArguments;ShowRandomPersonNumber;Connect;SavePerson;InsertPerson\"\nWrite-Host \"Environment variable  $env:InterceptMethods  has been set to \" $env:InterceptMethods\ndotnet clean\ndotnet restore\ndotnet build /p:EmitCompilerGeneratedFiles=true --disable-build-servers --force\n#debug only\n# dotnet run --project RSCG_InterceptorTemplateConsole/RSCG_InterceptorTemplateConsole.csproj\n\n```\n\nEnjoy!\n\n# More Roslyn Source Code Generators\n\nYou can find more RSCG with examples at [Roslyn Source Code Generators](https://ignatandrei.github.io/RSCG_Examples/v2/)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fignatandrei%2Frscg_interceptortemplate","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fignatandrei%2Frscg_interceptortemplate","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fignatandrei%2Frscg_interceptortemplate/lists"}