Stroniax
Builder Pattern as Ref Struct
Hey all, I'm trying to make a source-generated builder which I want to be a struct. I'm running into a problem when trying to chain the entire build, but if I capture the builder in a variable first I can chain it as much as I like. Wondering if there's any language feature/etc that would help me out here? What I'd like is to use the same builder struct instance and not have to copy it with each chained method.
EDIT:
The problem occurs because the extension method operates on a
ref
of the instance, so I must have a field/variable declared beforehand of the type. This means I can't just call new().Extension()
, as the result of new()
must be assigned to something before it can be used. That is what I am trying to resolve.58 replies
❔ Non-Dictionary Default Json Converter
I have an interface I have to implement which is derived from
IReadOnlyDictionary<,>
. This must be implemented by many classes. I don't want to write custom converter logic for all of these types, is there a way to tell the System.Text.Json.JsonSerializer
to not use the dictionary converter and instead to use its regular converter logic for these types?2 replies
✅ How Does StreamReader.ReadLine Know When to Stop?
I am working with streams and don’t want to grab more data than I need from the stream. I realized somehow a streamreader knows when to stop reading, but I can’t imagine it reads one byte at a time to find the terminator character. How does it know when it has read enough and not consume more of the buffer?
2 replies
✅ HTTP/3 Server Without AspNetCore
For a work-related project I'm setting up a small local http API that allows applications for IPC or sys admins for troubleshooting to check on an application's state. It only has to have read endpoints for four resources and a POST endpoint for one other. I don't want to bloat the application with the entire AspNetCore suite - and when I tried to just reference the Kestrel library I had compatibility errors, looks like it hasn't been updated to work with later versions of
Microsoft.Extensions.Primitives
that I'm referencing. (Kestrel also leans heavily on the built-in DI which I don't want to use.)
I started going the route of HttpListener
, which is missing only a few features I'd like such as a RequestAborted
cancellation token when a request is received, and some poor async APIs (e.g. no CancellationToken
parameter). However, I was reading recently about HTTP/3 and would like to support that (don't need to worry about prior HTTP versions if I can support HTTP/3). I don't know how I can do that from HttpListener.
Is there another well-tested, modern way to host an HTTP API as part of an application, particularly one that supports HTTP/3?12 replies
✅ Struct Fields
Is there a reason to mask two values into a single field on a struct, e.g. if I want a
struct MyValue
with fields ushort A
and ushort B
, is there any value in having the struct internally store the value as uint _c
? I formerly thought since this was one field it was better because everyone says to generally not use a struct with a lot of fields, but based on some reading I have done it seems that maybe this is treated in memory the same way since those two ushort fields are side-by-side and effectively storing two ushort fields would be no different except that I wouldn't have to manually unmask A
and B
from _c
in my getters.12 replies
❔ Read Stream to End of Json Object
I am trying to read a stream from the beginning of a json object until the end of a json object, without reading until the end of the stream. This is specifically meant for things like deserializing a TcpClient's NetworkStream where the stream will not close until I have sent a response and the other end closes. Currently, calling
JsonSerializer.Deserialize(stream
will not return until the other end calls TcpClient.Close()
which means I can't get the full request object and therefore can't send a response that the other end is waiting for.2 replies
❔ EF Core Sql Server JsonDocument
I am trying to use Entity Framework Core to map and access a json column. With EF 7, I believe that is supported (via the the
ToJson(OwnedNavigationBuilder, string)
extension method). However, the value is not a consistent schema, so I cannot map a constant type. I want to use JsonDocument
but am getting a number of errors, making me wonder if that is actually possible? The only documentation I can find referencing mapping a JsonDocument property is using npgsql, and I don't see any references to JsonDocument
in the SQL Server EF core articles I am finding.2 replies
dotnet watch run FileNotFoundException (System.Runtime 7.0)
After updating Visual Studio, which installed the .NET 7.0 SDK, I can no longer use
dotnet watch run
on my project. I have made no other changes (all target frameworks are still 6.0). dotnet run
works just fine, but when I use dotnet watch run
the solution builds and then fails with the following exception:
I was expecting that the update alone wouldn't break anything, at least until I updated my project(s)... I can't find anything on Google except for creating a global.json
file or possibly changing the target framework, which I do not yet want to do because I want to stick with LTS for this project.2 replies
Windows Interactive Logon [Answered]
I have been tasked with writing a program that connects to a remote computer and unlocks the workstation (logging in) with credentials supplied by the remote process. The remoting part is not a concern to me, but I am not finding any way to unlock the device programatically.
I have looked at
advapi32.dll
's LogonUser
function but I still do not know how to use the token to unlock the workstation. I'm having trouble finding what I want because Google is very over-saturated with content that matches the search terms I'm using because everybody has logon problems, and I'm not sure how to be more specific to Google about what I need.6 replies
EF Core SQL Generation with Custom Type [Answered]
I've got a custom type
AssetId
, which is an AK member of the type Asset
.
The AssetId
type is internally an int
, but for a number of reasons including the fact that it logically contains two values, it is stored as char(8)
in the db.
No matter how I configure this type, it seems querying against it in EF is always generating SQL like the following:
CONVERT(Asset.AssetId as NVARCHAR(max)) = N'00-00-00'
(where 00-00-00 is an AssetId.ToString()
). I do not want to convert the value to NVARCHAR(max)
for this. It shouldn't have to change from char(8)
at all.18 replies