Skip to content

Latest commit

 

History

History

2021-01-05

A PowerShell Conversion Challenge

For this challenge, I wrote a seriers of extensive walk-through articles.

Part 1

In the part 1 article, I cover the basics for PowerShell objects and classes, Get-Member command, the Requires statement, ValueFromPipeline, and the StringBuilder class. My solution (part 1) solved 7 primary requirements and 1 personal requirement.

Standard

  • Copy selected properties
  • [] Insert placeholder for methods
  • Work from pipeline
  • Allow user to specify a new class name
  • Support Windows PowerShell 5.1 and PowerShell 7.x

Bonus

  • Allow the user to include or exclude properties
  • Include a placeholder for a constructor
  • [] Let the user specify a method
  • [] Be VSCode aware an insert the new class automatically into the current file
  • Support cross-platform

Personal

  • [] Contained in a small module, as there will be a few private functions.
  • [] Use an existing PSCustomObject with non-conventional property names.
    • [] A private function would be used to enforce proper PascalCase casing and removal of punctuation (with maybe exception of period).
  • [] Should be recursive.
    • [] Any object that contains a property which is itself another complex object should generate a separate class definition.
  • Generate two constructors:
    • [] One empty constructor to create a clean instance of the class.
    • [] One constructor that will use the input object to populate a new instance.
  • [] Allow user to specify hidden properties.
  • [] If not specified, detect the property type and include in definition.

Part 2

In part 2, I solved 3 personal requirements, which included converting property and class names to PascalCase, detecting property types, and hiding properties.

Primary

  • [] Insert placeholder for methods
  • [] Let the user specify a method
  • [] Be VSCode aware an insert the new class automatically into the current file

Personal

  • [] Contained in a small module, as there will be a few private functions.
  • Use an existing PSCustomObject with non-conventional property names.
    • A private function would be used to enforce proper PascalCase casing and removal of punctuation (with maybe exception of period).
  • [] Should be recursive.
    • [] Any object that contains a property which is itself another complex object should generate a separate class definition.
  • Allow user to specify hidden properties.
  • If not specified, detect the property type and include in definition.

Part 3

In part 3, I solved 2 primary requirements and the remaining of my personal requirements, which included adding class methods and recursive capability to the ConvertTo-ClassDefinition function.

Primary

  • Insert placeholder for methods
  • Let the user specify a method
  • [] Be VSCode aware an insert the new class automatically into the current file

Personal

  • Contained in a small module, as there will be a few private functions.
  • Should be recursive.
    • Any object that contains a property which is itself another complex object should generate a separate class definition.