85 lines
2.6 KiB
C#
85 lines
2.6 KiB
C#
#nullable enable
|
|
using bts;
|
|
|
|
using System;
|
|
using System.Text.Json.Serialization;
|
|
|
|
namespace BCG {
|
|
/// <summary>
|
|
/// Resprsents information about a column schema, ie its ordinal, the type, the name and constant value or expression. where applicable
|
|
/// </summary>
|
|
[Serializable]
|
|
public class ColumnInfo : IEquatable<ColumnInfo>, IComparable<ColumnInfo>, IComparable, ICloneable<ColumnInfo> {
|
|
|
|
//the default column info does not cach values in a lookup table, therefore it is in group 0
|
|
public ColumnInfo(string colName, int colNo, Type colType, object? colValue = null) {
|
|
myColName = colName;
|
|
myColNo = colNo;
|
|
myColType = colType;
|
|
myColValue = colValue;
|
|
}
|
|
|
|
public ColumnInfo(string col_name, int col_no, TypeCode type_code)
|
|
: this(col_name, col_no, BlueDataUtility.get_type(type_code)) {
|
|
}
|
|
|
|
public static bool isAllowedType(Type type) =>
|
|
type == typeof(bool) ||
|
|
type == typeof(byte) ||
|
|
type == typeof(int) ||
|
|
type == typeof(long) ||
|
|
type == typeof(double) ||
|
|
type == typeof(string) ||
|
|
type == typeof(DateTime) ||
|
|
type == typeof(TimeSpan) ||
|
|
(type.IsEnum && isAllowedType(type.GetEnumUnderlyingType())) ||
|
|
(type.IsNullable() && isAllowedType(type.GetGenericArguments()[0]));
|
|
|
|
public int CompareTo(ColumnInfo? other) =>
|
|
other is null ? 1 : colNo.CompareTo(other.colNo);
|
|
|
|
public int CompareTo(object? obj) =>
|
|
CompareTo(obj as ColumnInfo);
|
|
|
|
public ColumnInfo Clone() =>
|
|
new(colName, colNo, colType);
|
|
|
|
public bool Equals(ColumnInfo? other) =>
|
|
other is not null
|
|
&& colNo == other.colNo
|
|
&& colType == other.colType
|
|
&& colName == other.colName;
|
|
|
|
public override bool Equals(object? obj) =>
|
|
Equals(obj as ColumnInfo);
|
|
|
|
public override int GetHashCode() =>
|
|
HashCode.Combine(colNo, colType, colName);
|
|
|
|
public override string ToString() {
|
|
return colName + " " + colNo + " " + colType;
|
|
}
|
|
|
|
|
|
// for backwards compatibility to allow build
|
|
public bool isConstant {get{return myColValue != null;}}
|
|
|
|
private int myColNo;
|
|
private string myColName;
|
|
private Type myColType;
|
|
private object? myColValue;
|
|
|
|
[JsonPropertyName("colNo")]
|
|
public int colNo { get { return myColNo; } }
|
|
|
|
[JsonPropertyName("colName")]
|
|
public string colName { get { return myColName; } }
|
|
|
|
[JsonPropertyName("colType")]
|
|
public Type colType { get { return myColType; } }
|
|
|
|
[JsonIgnore]
|
|
public object? colValue {get{return myColValue;}}
|
|
}
|
|
}
|