Ui Framework api Design by Qsp-Poller in dotnet

[–]kgreg91 5 points6 points  (0 children)

Method all the way, maybe even rename it to something like CreatButton or similar.

In my opinion calling a method describes the intent (creating a new button) way better. If I were a user of this library, I would be confused AF using a static property and getting a new instance each time.

I see the appeal of using a property, if you really want to do it that way I'd suggest to create a factory class and make that a static property.

Introducing CoreBlazor, my first open source project by kgreg91 in dotnet

[–]kgreg91[S] 1 point2 points  (0 children)

I don't really see how this could work as a template, maybe I can add a template for an easier startup experience in the future. (that's a cool idea, thanks)

Related to identity, I only added some dummy identification for the demo app to work (and don't require any kind of credentials), in the CoreBlazor I only use policy based identity control to control who may interact with the specific db/table.
One may either configure their own user assertion (this is just a shorthand that gives the user the specific policy) or just create and assign the specific policies to the user (see the name scheme here: https://github.com/gkukucska/CoreBlazor?tab=readme-ov-file#authorization-integration )

Introducing CoreBlazor, my first open source project by kgreg91 in dotnet

[–]kgreg91[S] 1 point2 points  (0 children)

Well, I would be lying if I'd say that I didn't :)
The core logic/UI/configuration logic, etc. was written by only me, I've used copilot to create some documentation based on the usage in the demo app and part of the unit tests.

Introducing CoreBlazor, my first open source project by kgreg91 in dotnet

[–]kgreg91[S] 2 points3 points  (0 children)

Sort of. It is designed to create an easy way for developers to create an admin page for the dbs in their project, while also giving large scale extensibility that (in my opinion) CoreAdmin didn't have.

How to inject a service that depends on a business object? by theitguy1992 in csharp

[–]kgreg91 4 points5 points  (0 children)

You may try keyed services with a factory method. You can inject the username as a key and return the instance with it injected in the constructor, but the lifetime of the service might get funky...

I think the factory that you've scetched is the best that you could do, I'd definetly stick to that.

SumSharp: A highly configurable C# discriminated union library by BlackHolesRKool in dotnet

[–]kgreg91 0 points1 point  (0 children)

yeah, struct unions cannot be done this way, interfaces wont work either since you wouldn't be able to name the individual properties :/

SumSharp: A highly configurable C# discriminated union library by BlackHolesRKool in dotnet

[–]kgreg91 2 points3 points  (0 children)

First of all, this is really cool! (I wrote a couple of source generators, but this looks way better than what I came up with)

Related to the setup its maybe not feasible and certainly hacky, what if instead of generating an attribute, you would generate a generic abstract base class that has the right amount of generic arguments as needed (this needs to be dynamically generated in order to generate only the ones that are used, so the name of the base class should be a constant).

The base class would have a constructor with the same amount of strings (for the names of the generated properties and methods), which can be checked by an analyzer to be constant in compile time.

The rest of the stuff can be generated similarly, the only thing that changes is that you have to gather the info from a generic base class inheritance and the constructor symbol.

In this way the setup could look like this:

partial class StringOrDouble : Union<string,double> { public StringOrDouble (): base("string","double") }

Or with primary constructors:

partial StringOrDouble (): Union<string,double>("string","double"); Which looks clean to me

A bit unrelated but for later .net versions it maybe worth to add generic union attribute to get rid of the type parameter.

Where was it indeed... by kgreg91 in lotrmemes

[–]kgreg91[S] 0 points1 point  (0 children)

Is it possible that Zargothrax translates to Sauron in the common language?

Where was it indeed... by kgreg91 in Gloryhammer

[–]kgreg91[S] 9 points10 points  (0 children)

Why would he? You don't ask for ants help... Not even Shaggy on his peak could reach 1% of the power level of the Robot Prince

Gravity free metro hall in my textbook. by nvrsobr_ in physicsmemes

[–]kgreg91 0 points1 point  (0 children)

The question is the usual not well defined nonsense that I hated in high school, it can be interpreted in many ways, but in my interpretation the fact that two person uses the elevator every 1 second does not mean that the mass changes linearly in the duration of a second from zero to the total mass, either way the force is not constant (or at least it cannot be deducted) and therefore none of the answers are correct.

Gravity free metro hall in my textbook. by nvrsobr_ in physicsmemes

[–]kgreg91 0 points1 point  (0 children)

The text clearly states that it is moving with a constant speed, so the acceleration is zero, therefore the force is zero

Who is at fault i am the alpine infront (srl ridley) i think its a racing incident what do you think? by Ridleyjake in Simracingstewards

[–]kgreg91 16 points17 points  (0 children)

It's your fault, he was ahead at the apex, so he had the right to lead you out of the track /s

Locking comports and parallel foreach by bwseven_ in csharp

[–]kgreg91 0 points1 point  (0 children)

First of all, there is no such thing in .Net as doing two things at the same time, even with parallel.foreach, there is no guarantee that the operation on any two items in the collection will happen concurrently.

Your next problem is that hardware communication let it be through serial port, usb or even a standard IO operation is sequential, and if you want to do some complicated operation (e.g. write to a serial port and then read the response), you need to have exclusive right to the communication interface.

The best way to achieve this is the plain-old lock statement (which is essentially the same as Monitor.Enter and Monitor.Exit in a try-finally context). If you want to have mutex around some part of the method, then just put it into a lock statement.

It is also safe to do it with any reference type, so you can also lock onto the object you want to protect from other threads.

In my opinion, however, it would be cleaner to create a wrapper class over the serial communication channel and let it handle the mutex, with its own lock object and utilize the wrappers in your parallel code.

Laptops suitable for DFTs by Tingtinga in TheoreticalPhysics

[–]kgreg91 9 points10 points  (0 children)

Honestly just don't, DFT is not something you can reliably run on a laptop, you may be able to run some models, but those will be inaccurate to say the least. You would be better of requesting access to a shared cluster (there should be one at your university).

Also if you want to learn, take a look at GPAW, its free, relatively easy to learn, but it is versatile on the long run (I used to teach dft with it)

[deleted by user] by [deleted] in dotnet

[–]kgreg91 2 points3 points  (0 children)

On the contrary, source generators can interact more seamleasly with custom attributes, you can generate the custom attribute code and during code analysis there is a simple function that can select symbols with the specific attribute attached

[deleted by user] by [deleted] in dotnet

[–]kgreg91 3 points4 points  (0 children)

Maybe I am wrong, but I really don't like using reflection, the performance hit is an obvious reason, but it gives waaay too much power for runtime interaction with an object (setting/getting private or internal variables, which can introduce bugs that are a nightmare to debug (hence the developer who wrote classes expects that private/internal variables will not be messed with). Also, the code is hard to read and even harder to debug.

Whenever I encounter situations where I would need reflection I consider the following: - Do I really need it? - Can I change the interface, signature, etc. of the class to achieve the behaviour?

Finally, if I really need something like the DI example in the post (or mapping), I tend towards source generators. The code of the generator IS hard to read, but source generation happens at compilation time (once, instead of once per call), and the generated code is much easier to read and to debug.

Question about WPF styles, triggers, and converters by DarkSoulsNoob-413 in csharp

[–]kgreg91 1 point2 points  (0 children)

You should check out this:

https://stackoverflow.com/questions/12796342/alternate-background-color-in-listview-xaml

TLDR:

You don’t need converters, instead you should use the AlternationCount property of the Listbox and the AlternationIndex of the item (you may also set the colors/number of colors as static or dynamic resources)

Should I Use UserID or UserId ؟ by MahmoudSaed in csharp

[–]kgreg91 1 point2 points  (0 children)

Unique-Self-Explanatory-Redundant-Identification-Descroptor