Skip to content
Merged
12 changes: 2 additions & 10 deletions sources/TileDB.CSharp/Array.cs
Original file line number Diff line number Diff line change
Expand Up @@ -501,15 +501,11 @@ static void GetDomain<T>(Array array, string dimName, uint i, NonEmptyDomain non
/// <exception cref="ArgumentException"><typeparamref name="T"/> is not the dimension's type.</exception>
public (T Start, T End, bool IsEmpty) NonEmptyDomain<T>(uint index) where T : struct
{
var datatype = EnumUtil.TypeToDataType(typeof(T));
using (var schema = Schema())
using (var domain = schema.Domain())
using (var dimension = domain.Dimension(index))
{
if (datatype != dimension.Type())
{
throw new ArgumentException("Array.NonEmptyDomain, not valid datatype!");
}
ErrorHandling.CheckDataType<T>(dimension.Type());
}

SequentialPair<T> data;
Expand All @@ -531,15 +527,11 @@ static void GetDomain<T>(Array array, string dimName, uint i, NonEmptyDomain non
/// <exception cref="ArgumentException"><typeparamref name="T"/> is not the dimension's type.</exception>
public (T Start, T End, bool IsEmpty) NonEmptyDomain<T>(string name) where T : struct
{
var datatype = EnumUtil.TypeToDataType(typeof(T));
using (var schema = Schema())
using (var domain = schema.Domain())
using (var dimension = domain.Dimension(name))
{
if (datatype != dimension.Type())
{
throw new ArgumentException("Array.NonEmptyDomain, not valid datatype!");
}
ErrorHandling.CheckDataType<T>(dimension.Type());
}

using var ms_name = new MarshaledString(name);
Expand Down
164 changes: 161 additions & 3 deletions sources/TileDB.CSharp/Enums.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System;
using System.ComponentModel;
using System.Text;
using TileDB.Interop;

namespace TileDB.CSharp
Expand Down Expand Up @@ -185,156 +186,294 @@ public enum DataType : uint
/// <summary>
/// A signed 32-bit integer.
/// </summary>
/// <remarks>
/// On generic methods operating to objects of this datatype,
/// this datatype can be used with <see cref="int"/>.
/// </remarks>
Int32 = tiledb_datatype_t.TILEDB_INT32,
/// <summary>
/// A signed 64-bit integer.
/// </summary>
/// <remarks>
/// On generic methods operating to objects of this datatype,
/// this datatype can be used with <see cref="long"/>.
/// </remarks>
Int64 = tiledb_datatype_t.TILEDB_INT64,
/// <summary>
/// A 32-bit floating-point number.
/// </summary>
/// <remarks>
/// On generic methods operating to objects of this datatype,
/// this datatype can be used with <see cref="float"/>.
/// </remarks>
Float32 = tiledb_datatype_t.TILEDB_FLOAT32,
/// <summary>
/// A 64-bit floating-point number.
/// </summary>
/// <remarks>
/// On generic methods operating to objects of this datatype,
/// this datatype can be used with <see cref="double"/>.
/// </remarks>
Float64 = tiledb_datatype_t.TILEDB_FLOAT64,
/// <summary>
/// A signed 8-bit integer.
/// </summary>
/// <remarks>
/// On generic methods operating to objects of this datatype,
/// this datatype can be used with <see cref="sbyte"/>.
/// </remarks>
Int8 = tiledb_datatype_t.TILEDB_INT8,
/// <summary>
/// An unsigned 8-bit integer.
/// </summary>
/// <remarks>
/// On generic methods operating to objects of this datatype,
/// this datatype can be used with <see cref="byte"/>.
/// </remarks>
UInt8 = tiledb_datatype_t.TILEDB_UINT8,
/// <summary>
/// A signed 16-bit integer.
/// </summary>
/// <remarks>
/// On generic methods operating to objects of this datatype,
/// this datatype can be used with <see cref="short"/>.
/// </remarks>
Int16 = tiledb_datatype_t.TILEDB_INT16,
/// <summary>
/// An unsigned 16-bit integer.
/// </summary>
/// <remarks>
/// On generic methods operating to objects of this datatype,
/// this datatype can be used with <see cref="ushort"/>.
/// </remarks>
UInt16 = tiledb_datatype_t.TILEDB_UINT16,
/// <summary>
/// An unsigned 32-bit integer.
/// </summary>
/// <remarks>
/// On generic methods operating to objects of this datatype,
/// this datatype can be used with <see cref="uint"/>.
/// </remarks>
UInt32 = tiledb_datatype_t.TILEDB_UINT32,
/// <summary>
/// An unsigned 64-bit integer.
/// </summary>
/// <remarks>
/// On generic methods operating to objects of this datatype,
/// this datatype can be used with <see cref="ulong"/>.
/// </remarks>
UInt64 = tiledb_datatype_t.TILEDB_UINT64,
/// <summary>
/// An ASCII string.
/// </summary>
/// <remarks>
/// On generic methods operating to objects of this datatype,
/// this datatype can be used with <see cref="byte"/>.
/// </remarks>
StringAscii = tiledb_datatype_t.TILEDB_STRING_ASCII,
/// <summary>
/// A UTF-8 string.
/// </summary>
/// <remarks>
/// On generic methods operating to objects of this datatype,
/// this datatype can be used with <see cref="byte"/>.
/// </remarks>
StringUtf8 = tiledb_datatype_t.TILEDB_STRING_UTF8,
/// <summary>
/// A UTF-16 string.
/// </summary>
/// <remarks>
/// On generic methods operating to objects of this datatype,
/// this datatype can be used with <see cref="ushort"/> or <see cref="char"/>.
/// </remarks>
StringUtf16 = tiledb_datatype_t.TILEDB_STRING_UTF16,
/// <summary>
/// A UTF-32 string.
/// </summary>
/// <remarks>
/// On generic methods operating to objects of this datatype,
/// this datatype can be used with <see cref="uint"/>.
/// </remarks>
StringUtf32 = tiledb_datatype_t.TILEDB_STRING_UTF32,
/// <summary>
/// A date and time, counted as the signed 64-bit number of
/// years since the Unix epoch (January 1 1970 at midnight).
/// </summary>
/// <remarks>
/// On generic methods operating to objects of this datatype,
/// this datatype can be used with <see cref="long"/>.
/// </remarks>
DateTimeYear = tiledb_datatype_t.TILEDB_DATETIME_YEAR,
/// <summary>
/// A date and time, counted as the signed 64-bit number of
/// months since the Unix epoch (January 1 1970 at midnight).
/// </summary>
/// <remarks>
/// On generic methods operating to objects of this datatype,
/// this datatype can be used with <see cref="long"/>.
/// </remarks>
DateTimeMonth = tiledb_datatype_t.TILEDB_DATETIME_MONTH,
/// <summary>
/// A date and time, counted as the signed 64-bit number of
/// weeks since the Unix epoch (January 1 1970 at midnight).
/// </summary>
/// <remarks>
/// On generic methods operating to objects of this datatype,
/// this datatype can be used with <see cref="long"/>.
/// </remarks>
DateTimeWeek = tiledb_datatype_t.TILEDB_DATETIME_WEEK,
/// <summary>
/// A date and time, counted as the signed 64-bit number of
/// days since the Unix epoch (January 1 1970 at midnight).
/// </summary>
/// <remarks>
/// On generic methods operating to objects of this datatype,
/// this datatype can be used with <see cref="long"/>.
/// </remarks>
DateTimeDay = tiledb_datatype_t.TILEDB_DATETIME_DAY,
/// <summary>
/// A date and time, counted as the signed 64-bit number of
/// hours since the Unix epoch (January 1 1970 at midnight).
/// </summary>
/// <remarks>
/// On generic methods operating to objects of this datatype,
/// this datatype can be used with <see cref="long"/>.
/// </remarks>
DateTimeHour = tiledb_datatype_t.TILEDB_DATETIME_HR,
/// <summary>
/// A date and time, counted as the signed 64-bit number of
/// minutes since the Unix epoch (January 1 1970 at midnight).
/// </summary>
/// <remarks>
/// On generic methods operating to objects of this datatype,
/// this datatype can be used with <see cref="long"/>.
/// </remarks>
DateTimeMinute = tiledb_datatype_t.TILEDB_DATETIME_MIN,
/// <summary>
/// A date and time, counted as the signed 64-bit number of
/// seconds since the Unix epoch (January 1 1970 at midnight).
/// </summary>
/// <remarks>
/// On generic methods operating to objects of this datatype,
/// this datatype can be used with <see cref="long"/>.
/// </remarks>
DateTimeSecond = tiledb_datatype_t.TILEDB_DATETIME_SEC,
/// <summary>
/// A date and time, counted as the signed 64-bit number of
/// milliseconds since the Unix epoch (January 1 1970 at midnight).
/// </summary>
/// <remarks>
/// On generic methods operating to objects of this datatype,
/// this datatype can be used with <see cref="long"/>.
/// </remarks>
DateTimeMillisecond = tiledb_datatype_t.TILEDB_DATETIME_MS,
/// <summary>
/// A date and time, counted as the signed 64-bit number of
/// microseconds since the Unix epoch (January 1 1970 at midnight).
/// </summary>
/// <remarks>
/// On generic methods operating to objects of this datatype,
/// this datatype can be used with <see cref="long"/>.
/// </remarks>
DateTimeMicrosecond = tiledb_datatype_t.TILEDB_DATETIME_US,
/// <summary>
/// A date and time, counted as the signed 64-bit number of
/// nanoseconds since the Unix epoch (January 1 1970 at midnight).
/// </summary>
/// <remarks>
/// On generic methods operating to objects of this datatype,
/// this datatype can be used with <see cref="long"/>.
/// </remarks>
DateTimeNanosecond = tiledb_datatype_t.TILEDB_DATETIME_NS,
/// <summary>
/// A date and time, counted as the signed 64-bit number of
/// picoseconds since the Unix epoch (January 1 1970 at midnight).
/// </summary>
/// <remarks>
/// <para>
/// One second consists of one trillion picoseconds.
/// </para>
/// <para>
/// On generic methods operating to objects of this datatype,
/// this datatype can be used with <see cref="long"/>.
/// </para>
/// </remarks>
DateTimePicosecond = tiledb_datatype_t.TILEDB_DATETIME_PS,
/// <summary>
/// A date and time, counted as the signed 64-bit number of
/// femtoseconds since the Unix epoch (January 1 1970 at midnight).
/// </summary>
/// <remarks>
/// <para>
/// One second consists of one quadrillion femtoseconds.
/// </para>
/// <para>
/// On generic methods operating to objects of this datatype,
/// this datatype can be used with <see cref="long"/>.
/// </para>
/// </remarks>
DateTimeFemtosecond = tiledb_datatype_t.TILEDB_DATETIME_FS,
/// <summary>
/// A date and time, counted as the signed 64-bit number of
/// attoseconds since the Unix epoch (January 1 1970 at midnight).
/// </summary>
/// <remarks>
/// <para>
/// One second consists of one quintillion attoseconds.
/// </para>
/// <para>
/// On generic methods operating to objects of this datatype,
/// this datatype can be used with <see cref="long"/>.
/// </para>
/// </remarks>
DateTimeAttosecond = tiledb_datatype_t.TILEDB_DATETIME_AS,
/// <summary>
/// A time of day counted in hours.
/// </summary>
/// <remarks>
/// On generic methods operating to objects of this datatype,
/// this datatype can be used with <see cref="long"/>.
/// </remarks>
TimeHour = tiledb_datatype_t.TILEDB_TIME_HR,
/// <summary>
/// A time of day counted in minutes.
/// </summary>
/// <remarks>
/// On generic methods operating to objects of this datatype,
/// this datatype can be used with <see cref="long"/>.
/// </remarks>
TimeMinute = tiledb_datatype_t.TILEDB_TIME_MIN,
/// <summary>
/// A time of day counted in seconds.
/// </summary>
/// <remarks>
/// On generic methods operating to objects of this datatype,
/// this datatype can be used with <see cref="long"/>.
/// </remarks>
TimeSecond = tiledb_datatype_t.TILEDB_TIME_SEC,
/// <summary>
/// A time of day counted in milliseconds.
/// </summary>
/// <remarks>
/// On generic methods operating to objects of this datatype,
/// this datatype can be used with <see cref="long"/>.
/// </remarks>
TimeMillisecond = tiledb_datatype_t.TILEDB_TIME_MS,
/// <summary>
/// A time of day counted in microseconds.
/// </summary>
/// <remarks>
/// On generic methods operating to objects of this datatype,
/// this datatype can be used with <see cref="long"/>.
/// </remarks>
TimeMicrosecond = tiledb_datatype_t.TILEDB_TIME_US,
/// <summary>
/// A time of day counted in nanoseconds.
/// </summary>
/// <remarks>
/// On generic methods operating to objects of this datatype,
/// this datatype can be used with <see cref="long"/>.
/// </remarks>
TimeNanosecond = tiledb_datatype_t.TILEDB_TIME_NS,
/// <summary>
/// A time of day counted in picoseconds.
Expand All @@ -349,12 +488,20 @@ public enum DataType : uint
/// </summary>
TimeAttosecond = tiledb_datatype_t.TILEDB_TIME_AS,
/// <summary>
/// A binary blob.
/// Binary data.
/// </summary>
/// <remarks>
/// On generic methods operating to objects of this datatype,
/// this datatype can be used with <see cref="byte"/>.
/// </remarks>
Blob = tiledb_datatype_t.TILEDB_BLOB,
/// <summary>
/// A boolean value.
/// </summary>
/// <remarks>
/// On generic methods operating to objects of this datatype,
/// this datatype can be used with <see cref="byte"/> or <see cref="bool"/>.
/// </remarks>
Boolean = tiledb_datatype_t.TILEDB_BOOL
}

Expand Down Expand Up @@ -1025,6 +1172,15 @@ public static DataType TypeToDataType(Type t)
}
}

/// <summary>
/// Gets the corresponding <see cref="Type"/> of a <see cref="DataType"/>.
/// </summary>
/// <param name="datatype">The datatype to convert.</param>
/// <remarks>
/// Some data types like <see cref="DataType.Boolean"/> and <see cref="DataType.StringUtf16"/>
/// correspond to both a numeric type like <see cref="ushort"/> and a non-numeric type like <see cref="char"/>.
/// This method will return the numeric type.
/// </remarks>
public static Type DataTypeToType(DataType datatype)
{
switch (datatype)
Expand Down Expand Up @@ -1056,10 +1212,12 @@ public static Type DataTypeToType(DataType datatype)
case DataType.Int8:
return typeof(sbyte);
case DataType.StringAscii:
case DataType.StringUtf8:
return typeof(byte);
case DataType.StringUtf16:
return typeof(ushort);
case DataType.StringUtf32:
case DataType.StringUtf8:
return typeof(sbyte);
return typeof(uint);
case DataType.TimeAttosecond:
case DataType.TimeFemtosecond:
case DataType.TimeHour:
Expand Down
Loading