I'm trying to pass a value constrained type to BitConverter.GetBytes, but c# only permits a struct constraint. For example:
private void writePrimitive<T>(T obj) where T : struct {
if (!typeof(T).IsPrimitive)
throw new ArgumentException("Only primitive types allowed");
Buffer.BlockCopy(BitConverter.GetBytes(obj), 0, buf, pos, sizeof(obj));
update(sizeof(obj));
}
The compiler understandably borks at this. Still I'd like to find a solution that avoids repetition and doesn't require writing multiple overloads for different primitives.
Hello,
There's a nice repo on GitHub at github.com/ItzLevvie/MicrosoftTeams-msinternal/ that lets you pull various versions of Microsoft Teams. You might want to try some of those to see if they work better.
As always, use caution when trusting random scripts on the internet.
Regards,
Aryeh Goretsky
Claude has always had issues with Windows, it prefers MacOS or Linux environments. You can see that with how badly it handles PowerShell commands and the fact up until recently tried using BASH commands in Windows.... That was with both Claude CLI and Claude Desktop. It does work well with a WSL environment to a degree. Not sure if these issue are fully resolved, but given the article I wouldn't be surprised if it hasn't.
Question
simplezz
Hi all,
I'm trying to pass a value constrained type to BitConverter.GetBytes, but c# only permits a struct constraint. For example:
private void writePrimitive<T>(T obj) where T : struct { if (!typeof(T).IsPrimitive) throw new ArgumentException("Only primitive types allowed"); Buffer.BlockCopy(BitConverter.GetBytes(obj), 0, buf, pos, sizeof(obj)); update(sizeof(obj)); }The compiler understandably borks at this. Still I'd like to find a solution that avoids repetition and doesn't require writing multiple overloads for different primitives.Link to comment
https://www.neowin.net/forum/topic/1266054-bufferblockcopy-passing-generic-argument/Share on other sites
2 answers to this question
Recommended Posts