- Powershell Core 6.2 Cookbook
- Jan Hendrik Peters
- 141字
- 2021-06-24 15:14:33
How it works...
Using C# to create your class libraries will allow you to reap the benefits of compiled assembly, such as greater execution speed, with the trade-off of having to acquire more software development skills. If you don't require all C# language features, such as LINQ, full control over member visibility and others, then PowerShell classes might be more suitable for you.
PowerShell classes lend themselves to serving as property bags and classes with simple properties and methods. PowerShell classes can contain static methods and inherit from other classes and interfaces, and combine the best of both worlds for many use cases.
In this recipe, you wrote your own class step by step by first adding class definitions to your code. Then, you applied parameter validation. Lastly, you saw that PowerShell classes are instantiated exactly like normal .NET classes are.