Last active
December 17, 2024 17:13
-
-
Save CN-CODEGOD/dd415e0ab67f5f900982bfa227b11c47 to your computer and use it in GitHub Desktop.
HOW to write the save method
This file contains hidden or 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
| Import-xml | |
| using namespace system.xml.linq | |
| class script { | |
| [scriptblock]$scriptblock | |
| [string]$name | |
| #1.add hidden path | |
| hidden [string]$path = "$PSScriptRoot\xml\script.xml" | |
| #2.init | |
| [void] DoInit( [pscustomobject]$pscustomobject){ | |
| $pscustomobjectName= (($pscustomobject)|Get-Member -Type NoteProperty ).Name | |
| foreach($propertyName in $pscustomobjectName ){ | |
| $this.$Propertyname= $pscustomobject.$Propertyname | |
| } | |
| } | |
| script ($pscustomobject){ | |
| $this.doinit($pscustomobject) | |
| } | |
| #3.save method | |
| [object] save(){ | |
| $object=[XElement]::new("object", | |
| [XAttribute]::new("name","script"), | |
| [XElement]::new("property",[XAttribute]::new("name","scriptblock"),$this.scriptblock), | |
| [XElement]::new("property",[XAttribute]::new("name","name"),$this.name) | |
| ) | |
| return $object.ToString() | |
| } | |
| } | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment