333fred
Object passed by reference unexpectedly
Take a look through some of the articles here: https://learn.microsoft.com/en-us/dotnet/csharp/tour-of-csharp/overview
39 replies
Object passed by reference unexpectedly
Depends on the context. In your case here, you'd probably take one of a few possible approaches:
1. Use a record for
TokenContext
, it probably should be one anyways. Then you wouldn't reassign individual properties like you're doing there, you'd with
to do non-destructive mutation
2. Use a builder for TokenContext
s. That's effectively what you're doing here, you're treating TokenContext
as if it was a builder. But combining these two things into one isn't great; you've opened yourself up to bugs because TokenContext
is mutable.
3. You could certainly make TokenContext
a struct
here. It's not the worst idea, given that there's only 5 pieces of data and they can presumably be enregistered by the JIT.
In any of these options, though, I would absolutely make TokenContext
immutable. After you create a Token
, there's almost certainly no reason to permit modification of TokenContext
39 replies