MartinGC94 / DisplayConfig

PowerShell module for configuring Windows display settings
MIT License
45 stars 2 forks source link

Getters for serialized objects #2

Closed Lucide closed 5 months ago

Lucide commented 5 months ago

Hi, it's me again 🙇‍♂️ I'd like to have access to getters for serialized configs. Use case: I need to load a config and set a resolution to its primary display before applying. The API.DisplayConfig class has a GetPrimaryDisplayId(), but a deserialized object has no methods. A way to do this would be with static methods in DisplayConfig. But then i read here, and it seems to me that the function is calling the SetDisplayResolution(id, Width, Height); method on an object from the pipeline. But this works with serialized objects too, why?🤔

Another way would be to have a constructor that takes a deserialized object and creates a "live object" instance. I found no explicit constructor for DisplayConfig but I can see one being used here, with what looks like a literal initialization.

MartinGC94 commented 5 months ago

Try importing the module before you import the clixml. The module includes special code to convert the custom object you get from Import-CliXml into an actual displayconfig, see: https://github.com/MartinGC94/DisplayConfig/blob/main/PowerShellTypeFiles/DisplayConfigType.ps1xml and https://github.com/MartinGC94/DisplayConfig/blob/main/src/DisplayConfig/API/DisplayConfigConverter.cs

Lucide commented 5 months ago

Ooh, that explains the inconsistent behaviour I was seeing in different pw sessions, I thought it was time for bed🤣. I would've never guessed,

thank you🙂