How to run tweak methods dynamically from JSON with parameters?
I'm building a WPF app that applies Windows tweaks like dark mode etc.
I've got a C# class
EssentialTweaks
, with public methods that return bool. Most are parameterless, some take enums like
.
Errors go to Console.WriteLine.
I want the UI to show all tweaks grouped by class (as categories), let users check what they want, and then apply them one by one even if some fail.
The goal is to define all tweaks in a JSON file with the name, description, class/method, and optional enum param — so the UI builds dynamically and I don’t have to hardcode anything. For things like PS5 vs PS7, each should be a separate entry in the list.
Here’s the repo: https://github.com/PUXSY/WinRep-Code
What’s the cleanest way to structure this? Ideally no crazy reflection or 100 buttons.
Any ideas appreciated 🙏
sorry if this looks AI generated, I just didn't know how to write it, not like a damassGitHub
GitHub - PUXSY/WinRep-Code
Contribute to PUXSY/WinRep-Code development by creating an account on GitHub.
3 Replies
The easiest way is probably just handcode since the list isnt't that long.
The second easiest is probably add an interface to tweaks that let's a caller know what tweaks it provides. Something like the below (with potentially higher complexity since some take parameters)
After that you're getting into something like reflection (which wouldn't be that hard) or making a source generator.
TBH though keep it simple until you have knowledge that you need it to be more.
I know I will have a ton of more tweaks, like I'm copying the WinUtil tweaks https://winutil.christitus.com/dev/, so what do you think? I think the easiest way is with an interface, but as you know, I'm going to add way more tweaks, so what do you think is the best way?
DI with an interface is a good design. You can use type hierarchy to add more complexity if needed