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.
- 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
| Name | Description |
|---|
| Value | Contains the value of the field, with the type specified by T. |
| IsChanged | Indicates whether the value of the field has been changed. |
Constructors
| Name | Description |
|---|
| 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
| Name | Description |
|---|
| GetObjectData(info, context) | Initializes a new instance of the DataField<T> class with the specified value. |
| GetValue() | Retrieves the encapsulated value. |
| ComparedTo(obj) | Compares the encapsulated value to another object. |
| Equals(other) | Determines whether the specified value is equal to the encapsulated value. |
| Equals(obj) | Determines whether the specified object is equal to the current DataField<T> instance. |
| Clone() | Creates a new DataField<T> instance with the same 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. |
| GetHashCode() | Returns a hash code for the encapsulated value. |
Generic Types
| Name | Description |
|---|
| T | Generic type of value property. |