In Powershell, I can do the following with a list
$obj = New-Object System.Object
foreach ($item in $list) {
$obj | Add-Member -type NoteProperty -name fname -value $item.firstname
$obj | Add-Member -type NoteProperty -name lname -value $item.lastname
}
$obj
and this will print out two columns with the first and last name.
In C#, i'm not sure how I can accomplish this. Do I need to create a custom class for each object? Or is there a way to do this dynamically in c# like in powershell?
The data i've got is in JSON. I can use JSON.net to iterate through the list of results but I'm not sure how to put them into an object such that
WriteObject(customObj);
will result in the same output as above.
By the way, this is all inside of a PSCmdlet
class so output will always go to the console/cmd window.
thank you.