Skip to main content

DataField<T>

The DataField<T> class is a generic data wrapper that provides additional functionality such as tracking changes, serialization, and comparison for a value of type T. It implements IDataField, IComparable, IComparable<T>, IEquatable<T>, ISerializable interfaces to support various behaviors.

The DataField<T> class also implements some operators.

operator ==, operator !=

  • Description: Determines equality or inequality between two DataField<T> instances.

operator >, operator <, operator >=, operator <=

  • Description: Compares two DataField<T> instances using their encapsulated values.

implicit operator DataField<T>(T value)

  • Description: Allows implicit conversion from a value of type T to a DataField<T>.

explicit operator T(DataField<T> value)

  • Description: Allows explicit conversion from a DataField<T> to its encapsulated value of type T.
Note
  • The IsChanged property is updated automatically whenever the Value changes.
  • Implements custom comparison logic for nullable and non-nullable types.
  • Designed to handle serialization and deserialization seamlessly.
  • Prevents infinite recursion in equality and comparison operations by carefully managing operator usage.

Properties

NameDescription
IsChangedIndicates whether the value of the field has been changed.
ValueContains the value of the field, with the type specified by T.

Constructors

NameDescription
DataField(value)Initializes a new instance of the DataField<T> class with the specified value.
DataField(info, context)Initializes a new instance of the DataField<T> class with the specified value.

Methods

NameDescription
Equals(obj)Determines whether the specified object is equal to the current DataField<T> instance.
GetValue()Retrieves the encapsulated value.
ToString()Returns a string representation of the value. If the value is null, returns an empty string.
ComparedTo(other)Compares the encapsulated value to another value of type T.
Clone()Creates a new DataField<T> instance with the same value.
GetObjectData(info, context)Initializes a new instance of the DataField<T> class with the specified value.
GetHashCode()Returns a hash code for the encapsulated value.
Equals(other)Determines whether the specified value is equal to the encapsulated value.
ComparedTo(obj)Compares the encapsulated value to another object.

Generic Types

NameDescription
TGeneric type of value property.