Add cmdlet for encoding serialized objects for PS

pull/33/head
Pat Hartl 2023-11-16 15:20:50 -06:00
parent ed1b4973d3
commit 8abc2fa15e
3 changed files with 26 additions and 1 deletions

View File

@ -9,7 +9,7 @@ namespace LANCommander.PowerShell.Cmdlets
{ {
[Cmdlet(VerbsData.ConvertFrom, "SerializedBase64")] [Cmdlet(VerbsData.ConvertFrom, "SerializedBase64")]
[OutputType(typeof(object))] [OutputType(typeof(object))]
public class ConvertFromSerializedBase64Cmdlet : PSCmdlet public class ConvertFromSerializedBase64Cmdlet : Cmdlet
{ {
[Parameter(Mandatory = true, Position = 0, ValueFromPipeline = true, ValueFromPipelineByPropertyName = true)] [Parameter(Mandatory = true, Position = 0, ValueFromPipeline = true, ValueFromPipelineByPropertyName = true)]
public string Input { get; set; } public string Input { get; set; }

View File

@ -0,0 +1,24 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Management.Automation;
using System.Text;
using System.Threading.Tasks;
namespace LANCommander.PowerShell.Cmdlets
{
[Cmdlet(VerbsData.ConvertTo, "SerializedBase64")]
[OutputType(typeof(object))]
public class ConvertToSerializedBase64Cmdlet : Cmdlet
{
[Parameter(Mandatory = true, Position = 0, ValueFromPipeline = true, ValueFromPipelineByPropertyName = true)]
public object Input { get; set; }
protected override void ProcessRecord()
{
var output = Convert.ToBase64String(Encoding.UTF8.GetBytes(PSSerializer.Serialize(Input)));
WriteObject(output);
}
}
}

View File

@ -46,6 +46,7 @@
<Reference Include="System.Xml" /> <Reference Include="System.Xml" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<Compile Include="Cmdlets\ConvertTo-SerializedBase64.cs" />
<Compile Include="Cmdlets\ConvertFrom-SerializedBase64.cs" /> <Compile Include="Cmdlets\ConvertFrom-SerializedBase64.cs" />
<Compile Include="Cmdlets\Edit-PatchBinary.cs" /> <Compile Include="Cmdlets\Edit-PatchBinary.cs" />
<Compile Include="Cmdlets\Uninstall-Game.cs" /> <Compile Include="Cmdlets\Uninstall-Game.cs" />