Skip to content

Commit bbcbb94

Browse files
committed
Fix type validation.
1 parent 3a0fe0a commit bbcbb94

File tree

5 files changed

+17
-19
lines changed

5 files changed

+17
-19
lines changed

sources/TileDB.CSharp/Array.cs

+6-6
Original file line numberDiff line numberDiff line change
@@ -498,14 +498,14 @@ static void GetDomain<T>(Array array, string dimName, uint i, NonEmptyDomain non
498498
/// <exception cref="ArgumentException"><typeparamref name="T"/> is not the dimension's type.</exception>
499499
public (T Start, T End, bool IsEmpty) NonEmptyDomain<T>(uint index) where T : struct
500500
{
501-
var datatype = EnumUtil.TypeToDataType(typeof(T));
502501
using (var schema = Schema())
503502
using (var domain = schema.Domain())
504503
using (var dimension = domain.Dimension(index))
505504
{
506-
if (datatype != dimension.Type())
505+
var datatype = dimension.Type();
506+
if (EnumUtil.DataTypeToType(datatype) != typeof(T))
507507
{
508-
throw new ArgumentException("Array.NonEmptyDomain, not valid datatype!");
508+
ThrowHelpers.ThrowTypeMismatch(datatype);
509509
}
510510
}
511511

@@ -528,14 +528,14 @@ static void GetDomain<T>(Array array, string dimName, uint i, NonEmptyDomain non
528528
/// <exception cref="ArgumentException"><typeparamref name="T"/> is not the dimension's type.</exception>
529529
public (T Start, T End, bool IsEmpty) NonEmptyDomain<T>(string name) where T : struct
530530
{
531-
var datatype = EnumUtil.TypeToDataType(typeof(T));
532531
using (var schema = Schema())
533532
using (var domain = schema.Domain())
534533
using (var dimension = domain.Dimension(name))
535534
{
536-
if (datatype != dimension.Type())
535+
var datatype = dimension.Type();
536+
if (EnumUtil.DataTypeToType(datatype) != typeof(T))
537537
{
538-
throw new ArgumentException("Array.NonEmptyDomain, not valid datatype!");
538+
ThrowHelpers.ThrowTypeMismatch(datatype);
539539
}
540540
}
541541

sources/TileDB.CSharp/DimensionLabel.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ public string GetUri()
129129
/// <inheritdoc/>
130130
public void Dispose()
131131
{
132-
throw new NotImplementedException();
132+
_handle.Dispose();
133133
}
134134
}
135135
}

sources/TileDB.CSharp/FragmentInfo.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -651,7 +651,7 @@ private static void ValidateDomainType<T>(DataType dataType)
651651
{
652652
ThrowHelpers.ThrowStringTypeMismatch(dataType);
653653
}
654-
if (dataType != EnumUtil.TypeToDataType(typeof(T)))
654+
if (EnumUtil.DataTypeToType(dataType) != typeof(T))
655655
{
656656
ThrowHelpers.ThrowTypeMismatch(dataType);
657657
}

sources/TileDB.CSharp/Query.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -913,7 +913,7 @@ public Tuple<ulong, ulong> FragmentTimestampRange(ulong idx)
913913

914914
private void CheckDataType<T>(DataType dataType)
915915
{
916-
if (EnumUtil.TypeToDataType(typeof(T)) != dataType)
916+
if (typeof(T) != EnumUtil.DataTypeToType(dataType))
917917
{
918918
if (!(dataType== DataType.StringAscii && (typeof(T)==typeof(byte) || typeof(T) == typeof(sbyte) || typeof(T) == typeof(string)))
919919
&& !(dataType == DataType.Boolean && typeof(T) == typeof(byte)))

sources/TileDB.CSharp/Subarray.cs

+8-10
Original file line numberDiff line numberDiff line change
@@ -118,12 +118,11 @@ public void SetSubarray<T>(params T[] data) where T : struct
118118
public void SetSubarray<T>(ReadOnlySpan<T> data) where T : struct
119119
{
120120
ErrorHandling.ThrowIfManagedType<T>();
121-
var dataType = EnumUtil.TypeToDataType(typeof(T));
122121
(var domainType, var nDim) = GetDomainInfo();
123122

124-
if (dataType != domainType)
123+
if (EnumUtil.DataTypeToType(domainType) != typeof(T))
125124
{
126-
ThrowHelpers.ThrowTypeMismatch(dataType);
125+
ThrowHelpers.ThrowTypeMismatch(domainType);
127126
}
128127
if (data.Length != nDim * 2)
129128
{
@@ -141,23 +140,22 @@ public void SetSubarray<T>(ReadOnlySpan<T> data) where T : struct
141140
private void ValidateLabelType<T>(string name) where T : struct
142141
{
143142
ErrorHandling.ThrowIfManagedType<T>();
144-
var dataType = EnumUtil.TypeToDataType(typeof(T));
145143
using var schema = _array.Schema();
146144
using var label = schema.DimensionLabel(name);
147-
if (label.DataType != dataType)
145+
if (EnumUtil.DataTypeToType(label.DataType) != typeof(T))
148146
{
149-
ThrowHelpers.ThrowTypeMismatch(dataType);
147+
ThrowHelpers.ThrowTypeMismatch(label.DataType);
150148
}
151149
}
152150

153151
private void ValidateType<T>(string name) where T : struct
154152
{
155153
ErrorHandling.ThrowIfManagedType<T>();
156-
var dataType = EnumUtil.TypeToDataType(typeof(T));
157154
using var schema = _array.Schema();
158155
using var domain = schema.Domain();
159156
using var dimension = domain.Dimension(name);
160-
if (dimension.Type() != dataType)
157+
var dataType = dimension.Type();
158+
if (EnumUtil.DataTypeToType(dataType) != typeof(T))
161159
{
162160
ThrowHelpers.ThrowTypeMismatch(dataType);
163161
}
@@ -166,11 +164,11 @@ private void ValidateType<T>(string name) where T : struct
166164
private void ValidateType<T>(uint index) where T : struct
167165
{
168166
ErrorHandling.ThrowIfManagedType<T>();
169-
var dataType = EnumUtil.TypeToDataType(typeof(T));
170167
using var schema = _array.Schema();
171168
using var domain = schema.Domain();
172169
using var dimension = domain.Dimension(index);
173-
if (dimension.Type() != dataType)
170+
var dataType = dimension.Type();
171+
if (EnumUtil.DataTypeToType(dataType) != typeof(T))
174172
{
175173
ThrowHelpers.ThrowTypeMismatch(dataType);
176174
}

0 commit comments

Comments
 (0)