I am building an automation system using Powershell and I would like to define custom .Net types so that I can structure my application in a similar way to the other code I write.
At first, I tried using ‘Add-Type’ to import types from c# files into my application but I found this to be extremely painful to debug as a .net type can only be loaded once during per Powershell session. This means that when there are errors a single change to my code requires me to restart my app (I might as well be using C#).
At the moment I am simulating types in Powershell by using factory functions that dynamically generate PSObjects with the semantics I need. This does work but it is very verbose and I don’t seem to be able to declare private variables or methods for encapsulation.
Is there an easier way to achieve what I want?
If not....
Am I somehow barking up the wrong tree by wanting to write my Powershell code using abstract data types?
Is there a better way to structure my system that I should know about?
Can I achieve some encapsulation with what I am doing now?