Access values from a record without explicitly calling .Value
To keep it quite short, I have a record as followed
Now when I wanna use it, I simply do something like
The annoying part is, upon deserializing it and wanting to access it, I need to do
TestString.Value
. Is there a way to change the code snippet to simply not use .Value
at all? Quite new to records.8 Replies
How are you using this record?
Also btw you can change this to
public record ConfigurationValue<T>(T Value);
I did actually change it a lot. I even attempted to use an implicit operator to convert it automatically however, it worked only for non-list values.
To answer your question, im mainly using it as a regular model structure except, I am utilizing the record for extensive support.
so
is how I am using, just with the record of course.
There is no way to access
Value
implicitly, and you can't also rely on implicit casting because it won't work when T
is an interfaceI figured mid-way through that the implicit operator wouldn't work
So I reverted the code back to its original state
And since
Value
is T
then you can't really just "forward" the properties from T
So no, there is no good way to do thismhm, I was originally planning to keep the
.Value
in as annoying as it might be
I just don't wanna always explicitly call .Value
when it can be shortened to just TestString
I mean how wrong is this
ðŸ˜It'll work for non interface types, but the moment T is an interface it won't work 😅
yeah, I realized the hassle and simply kept the
.Value
in