I would like to try the new C# 12 preview function Interceptors but can't seem to get them to work.
The page says
Preview feature Introduced in Visual Studio 17.7, preview 3.
So I tried using Jetbrains Rider. Because I have seen Nick Chapsas Youtube video
My project file looks like this:
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net8.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<LangVersion>preview</LangVersion>
<Features>InterceptorsPreview</Features>
</PropertyGroup>
</Project>
I used the sample code from this page
I have looked at the Youtube video some more and saw that the InterceptsLocationAttribute
was in one of his helper files so I tried adding the code for that attribute to my code project.
Than the code compiles bus still not works. The code execution did not jump to the interception code.
Update: Now that Visual Studio 17.7, preview 3 has been released, it works as intended in visual studio preview
I got it working the changes are already in the main branch of https://github.com/dotnet/roslyn so by building that locally i can start a new version of visual studio and run the code in that. That makes it work, so I think Nick did the same.