Show / Hide Table of Contents

    IDataPacker.AddValue<TValue>([NotNull]this IDataPacker packer, [NotNull]string key, [NotNull]TValue value) Method

    .NET Standard 2.x

    Adds a value as an element to the IDataPacker object.

    Namespace: SnapObjects.Data

    Assembly: SnapObjects.Data.dll

    Syntax

    public static void AddValue<TValue>(
    [NotNull]this IDataPacker packer,
    [NotNull]string key,
    [NotNull]TValue value)
    

    Parameters

    key System.String

    The key for the element, which is the identifier of the element in the IDataPacker object.

    value TValue

    The value of the element to be added to the IDataPacker object.

    Examples

    The following code example adds a value "NameValue" as an element to the IDataPacker object and uses "Value" as the key name for this element.

    using SnapObjects.Data;
    using System;
    using System.Collections.Generic;
    using System.Data;
    
    namespace Appeon.ApiDoc.IDataPackerExamples
    {
        public class AddValueExample
        {
            private readonly SchoolContext _context;
    
            public AddValueExample(SchoolContext dataContext)
            {
                // Sets the data context.
                _context = dataContext;
            }
    
            public void Example()
            {
                var packer = new DataPacker();
    
                // Adds "NameValue" to the current IDataPacker
                packer.AddValue("Value", "NameValue");
    
                // Gets and shows the number of elements of IDataPacker
                Console.WriteLine("The element count: {0}", packer.Count.ToString());
    
                // Gets and shows the data value in JSON format
                Console.WriteLine(packer.GetTextString(DataFormat.Json));
    
                /* This code example produces the following output:
                
                The element count: 1
                {"Value":"NameValue"}
                */
            }
        }
    }
    

    Applies to

    .NET Standard

    2.x

    Back to top Generated by Appeon