I’m trying to make some PowerShell cmdlets in C# and created a DataChunk class for storing binary data. It just holding byte[] array. The goal was to read bytes from file into DataChunk to show it how I need it. So I wrote ToString() method. But it seems that PowerShell not using it. Why?
PS> $data = Read-BinaryData test.bin
PS> $data.GetType()
IsPublic IsSerial Name BaseType
-------- -------- ---- --------
True False DataChunk System.Object
This is what I need:
PS> $data.ToString()
07 65 20 AE F6 8D 4F 00 97 A8 33 C9 81 EB 80 AE 92 87 7D 08
This is how it works now:
PS> $data
Count
-----
20
The class is simple:
public class DataChunk
{
byte[] data;
public int Count => data.Length;
public override string ToString() { ... }
}
How to make my own class to show up in PowerShell like I need to?