Table of Contents

Class DataPair

Namespace
Cuemon
Assembly
Cuemon.Core.dll

Represents a generic way to provide information about arbitrary data.

public class DataPair
Inheritance
DataPair
Derived

Examples

The following example demonstrates how to use the and classes to represent named metadata with type information.

using System;
using Cuemon; // for DataPair, DataPair<T>

namespace MyApp.Examples;

public class DataPairExample
{
    public void Demonstrate()
    {
        // Create a generic DataPair<T> for compile-time type safety
        var pair = new DataPair<int>("Age", 30);
        Console.WriteLine(pair);
        // Output: Name: Age, Value: 30, Type: Int32

        Console.WriteLine(pair.Name);   // Age
        Console.WriteLine(pair.Value);  // 30
        Console.WriteLine(pair.Type);   // System.Int32
        Console.WriteLine(pair.HasValue); // True

        // Create a non-generic DataPair
        var generic = new DataPair("CreatedAt", DateTime.UtcNow, typeof(DateTime));
        Console.WriteLine(generic);
        // Output: Name: CreatedAt, Value: ..., Type: DateTime

        // DataPair with null value
        var nullPair = new DataPair<string>("MiddleName", null);
        Console.WriteLine(nullPair.HasValue); // False
        Console.WriteLine(nullPair);
        // Output: Name: MiddleName, Value: <null>, Type: String

}
}

Constructors

DataPair(string, object, Type)

Initializes a new instance of the DataPair class.

public DataPair(string name, object value, Type typeOf)

Parameters

name string

The name of the data pair.

value object

The value of the data pair.

typeOf Type

The type of the data pair.

Properties

HasValue

Gets a value indicating whether Value is not null.

public bool HasValue { get; }

Property Value

bool

true if Value is not null; otherwise, false.

Name

Gets the name of the data pair.

public string Name { get; }

Property Value

string

The name of the data pair.

Type

Gets the type of the data pair value.

public Type Type { get; protected set; }

Property Value

Type

The type of the data pair value.

Value

Gets the value of the data pair.

public object Value { get; }

Property Value

object

The value of the data pair.

Methods

ToString()

Returns a string that represents this instance.

public override string ToString()

Returns

string

A string that represents this instance.