CatSandwich
CatSandwich
CC#
Created by CatSandwich on 9/14/2023 in #help
❔ Benefit of ref structs
Hey folks! I've been trying for a bit to understand the purpose of using a ref struct over a regular struct. I understand that it can only live on the stack, which is enforced via a set of usage rules, but regular structs could do that too if used properly. I asked my good old friend chatgpt to help me understand it, and the answer I got was basically that the compiler is able to optimize the usage of ref structs better given its restrictions. Is this accurate? Is it the only benefit? I'm used to concepts like the out keyword where its usage restrictions (must be populated by return, cannot be read) come as a tradeoff for visible benefits (inline variable declaration in a method call), so I guess I was expecting something similar in this case, specifically something that can only be done with ref structs.
60 replies
CC#
Created by CatSandwich on 8/4/2023 in #help
✅ Configure Xml Serialization
Hey folks! I have a type like this:
class DateTimeWrapper
{
public DateTime Value;
}
class DateTimeWrapper
{
public DateTime Value;
}
I'm serializing this via System.Xml. I would like to have this type serialize as if I were serializing the wrapped Value, rather than the whole type. In other words, I want it to serialize as this:
2023-08-04 00:00:00
2023-08-04 00:00:00
rather than
<Value>
2023-08-04 00:00:00
</Value>
<Value>
2023-08-04 00:00:00
</Value>
What are my options to make this happen? I would ideally like to avoid changing the serializer itself, but rather use an approach that the serializer will respect. For example, newtonsoft json uses JsonConverter, but I'm not sure if System.Xml has a similar concept.
18 replies
CC#
Created by CatSandwich on 1/3/2023 in #help
❔ How to close a process's handle?
6 replies