InternetException

Roslyn

Roslyn · 1 post (all tags)

Type is safe to use for equality in Roslyn source generators

· 338 words · ~1 min read · in .NET, C#

#source generators #records #Roslyn

Lately I am playing a lot with Roslyn Source Code generators. This allows you to do interesting things, like automatic generation of validation classes based on data in the domain layer. Or generating tests that check if your API endpoints return 200 OK when a bare GET request is sent.

One thing you have to remember to do is use types with strict value equality. Otherwise it may work incorrectly or it may leak memory. You can, for example, use records that do that for you, with the gotcha being no extra fields or properties. Because of that I was mostly translating Types into other values, i.e., the full name of the type, to avoid equality issues. But it turns out you can use it in IValueProvider directly.

Read the whole thing →