From 2527399da0aa7ae809918a6cf49234d611544842 Mon Sep 17 00:00:00 2001 From: onyx-and-iris <75868496+onyx-and-iris@users.noreply.github.com> Date: Thu, 6 Jan 2022 15:26:01 +0000 Subject: [PATCH] Create meta.ps1 meta functions for different property types moved into meta.ps1 --- lib/meta.ps1 | 52 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 52 insertions(+) create mode 100644 lib/meta.ps1 diff --git a/lib/meta.ps1 b/lib/meta.ps1 new file mode 100644 index 0000000..ecf2e31 --- /dev/null +++ b/lib/meta.ps1 @@ -0,0 +1,52 @@ +Function AddPublicMembers($this) { + [HashTable]$Signatures = @{} + ForEach($param in $this.bool_params) { + # Define getter + $Signatures["Getter"] = "`$this.Getter(`$this.cmd('{0}'))" -f $param + # Define setter + $Signatures["Setter"] = "param ( [Single]`$arg )`n`$this.Setter(`$this.cmd('{0}'), `$arg)" ` + -f $param + + Addmember + } + + ForEach($param in $this.float_params) { + # Define getter + $Signatures["Getter"] = "[math]::Round(`$this.Getter(`$this.cmd('{0}')), 1)" -f $param + # Define setter + $Signatures["Setter"] = "param ( [Single]`$arg )`n`$this.Setter(`$this.cmd('{0}'), `$arg)" ` + -f $param + + Addmember + } + + ForEach($param in $this.int_params) { + # Define getter + $Signatures["Getter"] = "[Int]`$this.Getter(`$this.cmd('{0}'))" -f $param + # Define setter + $Signatures["Setter"] = "param ( [Single]`$arg )`n`$this.Setter(`$this.cmd('{0}'), `$arg)" ` + -f $param + + Addmember + } + + ForEach($param in $this.string_params) { + # Define getter + $Signatures["Getter"] = "[String]`$this.Getter_String(`$this.cmd('{0}'))" -f $param + # Define setter + $Signatures["Setter"] = "param ( [String]`$arg )`n`$this.Setter(`$this.cmd('{0}'), `$arg)" ` + -f $param + + Addmember + } +} + +Function Addmember{ + $AddMemberParams = @{ + Name = $param + MemberType = 'ScriptProperty' + Value = [ScriptBlock]::Create($Signatures["Getter"]) + SecondValue = [ScriptBlock]::Create($Signatures["Setter"]) + } + $this | Add-Member @AddMemberParams +}