Skip to content

Commit

Permalink
Added create a Table from JSon string method
Browse files Browse the repository at this point in the history
  • Loading branch information
PiotrNestor committed Jun 28, 2024
1 parent 3981ff9 commit a234a90
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions Gauge.CSharp.Lib/Table.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@
* See LICENSE.txt in the project root for license information.
*----------------------------------------------------------------*/
using System;
using System.Runtime.Serialization.Json;
using System.IO;
using System.Text;
using System.Collections.Generic;
using System.Linq;

Expand Down Expand Up @@ -31,6 +34,16 @@ public Table(List<string> headers)
_tableRows = new List<TableRow>();
}

public Table FromJSon(string asJSon)
{
var serializer = new DataContractJsonSerializer(typeof(Table));
using (var ms = new MemoryStream(Encoding.UTF8.GetBytes(asJSon)))
{
var obj = serializer.ReadObject(ms);
return obj as Table;
}
}

/// <summary>
/// Add a row of data to the table.
/// </summary>
Expand Down

0 comments on commit a234a90

Please sign in to comment.