Pheubel
✅ Convert 3rd party Dictionary to usable variable
It's not gonna be the easiest thing around. If there was a page where you could stake out how the outputs can look, then you could have made a class with a similar structure, map the dictionary by looping over the key-value pairs of the dictionary (should be able to do that with a foreach iirc) and mapping each pair to a property of your class. But if there can be different results, then you can't really be sure you covered it all. If it isn't that important, you can just assume a single output and throw an exception when an unexpected key appears. Definitely not foolproof, but with low stakes you can just fiddle around until you are satisfied
4 replies
❔ ✅ Can I make this faster or should I start looking at load balancing? tell me your api speeds too
The curse of being stuck on old af dotnet. It is not great, you miss out on general runtime optimizations, evolved language syntax and security fixes. Your boss should take the initiative to allow upgrading the framework to more modern standards. In the end it will save money by being more performant, meaning nore requests before the need to expand; a wider ranger of programmers and better iteration speed due to the more modern syntax
225 replies
✅ Unable to read beyond the end of the stream.
my guess is that when you are trying to read from the memory stream, you are actually past the data you want to read out. Have a look at the
https://learn.microsoft.com/en-us/dotnet/api/system.io.memorystream?view=net-7.0
Position
property of your memory stream. my guess is that if the position is at 0, then it will work fine.https://learn.microsoft.com/en-us/dotnet/api/system.io.memorystream?view=net-7.0
5 replies
Best way to serialize a date without a year [Answered]
Maybe whatever you are using to serialize allows for custom converters, if so you could use that as an in between step to get the format you want.
It might also be useful to create your own struct with one byte for the month and one byte for the day. You can then add a conversion step to the DateOnly. Just spitballing the first things that come to mind
7 replies
A generic and efficient way to feed in text for a lexer or scanner
what i would do is instead of going over the source file again, go over it once and tokenize it and structure it in a tree immediately. then if you want to do multiple passes you can go to the tree instead and transform it
21 replies
A generic and efficient way to feed in text for a lexer or scanner
something i am doing is making use of a
TextReader
, it reads a stream of data going forwards only. there is a small problem with it tho, sometimes when you call Peek()
on it, it will assume that there is nothing to look for anymore, even though if you were to call Read()
it would return the next character. What i did was create a simple wrapper around it with a small internal buffer it can use to peek into.21 replies
Equals for structs [Answered]
it depends a bit. this article goes in depth about using it: https://docs.microsoft.com/en-us/dotnet/csharp/programming-guide/statements-expressions-operators/how-to-define-value-equality-for-a-type
but for just value holders you don't compare it is not that needed, if it is used for comparisons, then it makes sense to create an override that does it properly.
6 replies