✅ Convert 3rd party Dictionary to usable variable
I have the following code:
The record in question comes from PowerShell output from a 3rd party. The namespace, or type, is not publicly available unfortunately. Is there anything that can be done to make the key & value usable in this scenario?
2 Replies
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
I ended up flattening the output via powershell so I wouldn’t have to deal with the dictionary (still don’t know if I have all the possible keys). Because everything I tried in C#, the keys and values were always null. I couldn’t get it to convert, and I think it has to do with their enum as the key. Since it’s not publicly accessible, I think it’s having problems converting. I’m waiting for a response from the vendor, but I think flattening the response is the only option I have at the moment.
Their documentation doesn’t have anything on the PS results, or the enum. And the type isn’t exposed from their DLL either. It’s dumb