Created
February 23, 2024 20:54
-
-
Save andrewmatveychuk/f66e81864f2a96c8ff3a772b38cdc009 to your computer and use it in GitHub Desktop.
A sample PowerShell class for defining custom log entry objects
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
enum OperationResultList : byte { | |
Disabled | |
Deleted | |
Detected | |
} | |
class LogEntry { | |
[OperationResultList] $OperationResult | |
[ValidateNotNullOrEmpty()] [string] $OperationDetails | |
# Default constructor | |
LogEntry() { $this.Init(@{}) } | |
# Convenience constructor from hashtable | |
LogEntry([hashtable]$Properties) { $this.Init($Properties) } | |
# Common constructor for title and author | |
LogEntry([OperationResultList]$OperationResult, [string]$OperationDetails) { | |
$this.Init(@{OperationResult = $OperationResult; OperationDetails = $OperationDetails }) | |
} | |
# Shared initializer method | |
hidden [void] Init([hashtable]$Properties) { | |
foreach ($Property in $Properties.Keys) { | |
$this.$Property = $Properties.$Property | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment