C# to PS code feedback

Issue #138 new
Former user created an issue

Source code:

Chilkat.JsonObject json = new Chilkat.JsonObject();

bool success;

//  The only reason for failure in the following lines of code would be an out-of-memory condition..

//  An index value of -1 is used to append at the end.
int index = -1;

success = json.AddStringAt(-1,"Title","Pan's Labyrinth");
success = json.AddStringAt(-1,"Director","Guillermo del Toro");
success = json.AddStringAt(-1,"Original_Title","El laberinto del fauno");
success = json.AddIntAt(-1,"Year_Released",2006);

json.EmitCompact = false;
Console.WriteLine(json.Emit());
Debug.WriteLine("json Created!")

Converted code:

        [Chilkat.JsonObject]$json = (New-Object -TypeName Chilkat.JsonObject)
        [bool]$success
        [int]$index = ++1
        $success = $json.AddStringAt(++1,"Title","Pan's Labyrinth")
        $success = $json.AddStringAt(++1,"Director","Guillermo del Toro")
        $success = $json.AddStringAt(++1,"Original_Title","El laberinto del fauno")
        $success = $json.AddIntAt(++1,"Year_Released",2006)
        $json.EmitCompact = $false
        $Console.WriteLine($json.Emit())
        $Debug.WriteLine("json Created!")

problem:

1.Comment has been deleted

2.index = -1;

3.Console.WriteLine(json.Emit()); The correct one should be $json.Emit() | Out-Host or $($json.Emit())

4.Debug.WriteLine("json Created!") The correct one should be $("json Created!")

Comments (0)

  1. Log in to comment