Class DataColumn
- Namespace
- Datafication.Core.Data
- Assembly
- Datafication.Core.dll
Represents a concrete implementation of the IDataColumn interface.
[Serializable]
[DataContract]
public class DataColumn : IDataColumn
- Inheritance
-
objectDataColumn
- Implements
Constructors
DataColumn()
Initializes a new instance of the DataColumn class.
public DataColumn()
DataColumn(string, Type, string, bool, bool, bool, object, string)
Initializes a new instance of the DataColumn class with specified parameters.
public DataColumn(string name, Type dataType, string label = null, bool isNullable = true, bool isUnique = false, bool isIndexed = false, object defaultValue = null, string description = null)
Parameters
namestringThe name of the column.
dataTypeTypeThe type of data the column holds.
labelstringThe display label of the column.
isNullableboolA value indicating whether the column is nullable.
isUniqueboolA value indicating whether the column is unique.
isIndexedboolA value indicating whether the column is indexed.
defaultValueobjectThe default value of the column.
descriptionstringThe description providing additional context about the column.
Properties
DataType
Gets or sets the type of the data stored in the column.
[DataMember]
public SerializableType DataType { get; set; }
Property Value
DefaultValue
Gets or sets the default value of the column.
[DataMember]
public object DefaultValue { get; set; }
Property Value
- object
Description
Gets or sets the description of the column.
[DataMember]
public string Description { get; set; }
Property Value
- string
A string containing a detailed description of the column's purpose and content.
Examples
IDataColumn column = new DataColumn();
column.Name = "customer_age";
column.Label = "Age";
column.Description = "The age of the customer in years at the time of registration";
Remarks
The description provides additional context about the column's purpose, content, or usage. This can be useful for documentation, generating embeddings with richer context, or providing metadata for applications that need to understand the semantic meaning of the column.
Format
Gets or sets the format string used to display or serialize the column's values.
[DataMember]
public string Format { get; set; }
Property Value
- string
A string representing the format applied to column values during rendering or serialization.
Examples
IDataColumn column = new DataColumn();
column.Format = "0.00";
Console.WriteLine(string.Format(column.Format, 12.3456)); // Output: 12.35
Remarks
The format string follows standard .NET formatting conventions. For example:
"0.00"- For two decimal places (e.g., 12.34)."yyyy-MM-dd"- For date formatting (e.g., 2024-01-01).
IsIndexed
Gets or sets a value indicating whether the column is indexed.
[DataMember]
public bool IsIndexed { get; set; }
Property Value
- bool
IsNullable
Gets or sets a value indicating whether the column is nullable.
[DataMember]
public bool IsNullable { get; set; }
Property Value
- bool
IsPrimaryKey
Gets or sets a value indicating whether the column is a primary key.
[DataMember]
public bool IsPrimaryKey { get; set; }
Property Value
- bool
IsUnique
Gets or sets a value indicating whether the column is unique.
[DataMember]
public bool IsUnique { get; set; }
Property Value
- bool
Label
Gets or sets the label of the column.
[DataMember]
public string Label { get; set; }
Property Value
- string
Name
Gets or sets the name of the column.
[DataMember]
public string Name { get; set; }
Property Value
- string
Values
Gets or sets the values in the column.
[DataMember]
public List<object> Values { get; set; }
Property Value
- List<object>
Methods
Average()
Returns the average value of the DataColumn.
public double Average()
Returns
- double
The average value.
Clone()
Creates a copy of the column.
public IDataColumn Clone()
Returns
- IDataColumn
A new IDataColumn instance that is a copy of the current column.
ConvertType(Type, Func<object, object>)
Converts the values of the DataColumn to a new type using the provided conversion function. The DataType of the DataColumn is updated after the conversion.
public DataColumn ConvertType(Type targetType, Func<object, object> convertFunction)
Parameters
targetTypeTypeThe target Type to convert the DataColumn values to.
convertFunctionFunc<object, object>A function that converts the original values to the new type.
Returns
- DataColumn
The same DataColumn with updated values and DataType.
Examples
Example usage:
dataBlock["Survived"].Convert(typeof(string), v => (bool)v ? "Yes" : "No");
Exceptions
- InvalidCastException
Thrown when the conversion function's result does not match the target type.
GetFormattedValue(object)
Returns a formatted string representation of the given value based on the column's Format property.
public string GetFormattedValue(object value)
Parameters
valueobjectThe value to format. It should match the column's DataType.
Returns
- string
A string representation of the value, formatted according to the Format property.
Examples
IDataColumn column = new DataColumn();
column.Format = "{0} (lbs)";
string formattedValue = column.GetFormattedValue(12.34);
Console.WriteLine(formattedValue); // Output: "12.34 (lbs)"
Remarks
If the Format contains placeholders (e.g., "{0} (lbs)"), the value will be inserted into the placeholder.
If no Format is set, the default string representation of the value will be returned.
IsNumeric()
Determines whether all values in the DataColumn are numeric.
public bool IsNumeric()
Returns
- bool
True if all values are numeric, otherwise false.
Max()
Returns the maximum value in the DataColumn.
public double Max()
Returns
- double
The maximum value.
Min()
Returns the minimum value in the DataColumn.
public double Min()
Returns
- double
The minimum value.
Percentile(double)
Returns the specified percentile of the values in the DataColumn.
public double Percentile(double percentile)
Parameters
percentiledoubleThe percentile to calculate (e.g., 0.5 for median, 0.95 for 95th percentile).
Returns
- double
The calculated percentile value.
Size()
Returns the total items contained in the DataColumn.
public double Size()
Returns
- double
The total number of values.
StandardDeviation()
Returns the standard deviation of the values in the DataColumn.
public double StandardDeviation()
Returns
- double
The standard deviation of values.
Sum()
Returns the sum of all values in the DataColumn.
public double Sum()
Returns
- double
The sum of values.
ToDataBlock(DataColumn)
public static DataBlock ToDataBlock(DataColumn dataColumn)
Parameters
dataColumnDataColumn
Returns
ToString()
Returns a string representation of the column.
public override string ToString()
Returns
- string
A string that represents the column.
ValidateValue(object)
Validates whether a value matches the column type.
public bool ValidateValue(object value)
Parameters
valueobjectThe value to validate.
Returns
- bool
True if the value is valid; otherwise, false.
Variance()
Returns the variance of the values in the DataColumn.
public double Variance()
Returns
- double
The variance of values.