DataUnpacker.DataUnpacker(string raw, DataFormat format) Constructor
.NET Standard 2.x
Initializes a new instance of the DataUnpacker class.
Namespace: SnapObjects.Data
Assembly: SnapObjects.Data.dll
Syntax
public DataUnpacker(string raw, DataFormat format)
Parameters
raw System.String
A raw string which contains the data package.
The format of the data package must conform to the specified format.
format SnapObjects.Data.DataFormat
An enumerate value of the DataFormat enumeration.
It only supports DataFormat.Json so far.
Examples
The following code example creates a DataUnPacker object and calculates the number of elements in it.
using SnapObjects.Data;
using System;
using Appeon.ApiDoc.Models.School;
namespace Appeon.ApiDoc.DataUnpackerExamples
{
public class DataUnpackerExample
{
private readonly SchoolContext _context;
public DataUnpackerExample(SchoolContext dataContext)
{
// Sets the data context.
_context = dataContext;
}
public void Example()
{
var packer = new DataPacker();
var course = new Course()
{
CourseID = 1050,
Title = "Chemistry",
Credits = 4,
DepartmentID = 1
};
// Adds a model object.
packer.AddModel("Course", course);
// Adds a value.
packer.AddValue("name", "Name1");
var json = packer.GetTextString(DataFormat.Json);
// Creates a DataUnpacker object.
var dataUnPacker = new DataUnpacker(json, DataFormat.Json);
// Gets and shows the number of elements in dataUnPacker.
Console.WriteLine("The element count: {0}", dataUnPacker.Count.ToString());
/* This code example produces the following output:
The element count: 2
*/
}
}
}
Example Refer To
Model Class: Course
Applies to
.NET Standard
2.x