Skip to content

Commit

Permalink
Improve type checking for FragmentInfo methods when the type is str…
Browse files Browse the repository at this point in the history
…ing.

If the generic type is string, we check ourselves that the `DataType` is a string one. This ensures the exception thrown is `ArgumentException` instead of `TileDBException`.
The exception message also is more descriptive.
  • Loading branch information
teo-tsirpanis committed Oct 16, 2023
1 parent 8e3af2c commit 5ccc03f
Showing 1 changed file with 8 additions and 8 deletions.
16 changes: 8 additions & 8 deletions sources/TileDB.CSharp/FragmentInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -411,13 +411,13 @@ public ulong GetMinimumBoundedRectangleCount(uint fragmentIndex)
DataType dataType = GetDimensionType(fragmentIndex, dimensionIndex);
if (RuntimeHelpers.IsReferenceOrContainsReferences<T>())
{
if (typeof(T) == typeof(string))
if (typeof(T) == typeof(string) && EnumUtil.IsStringType(dataType))
{
(string startStr, string endStr) =
GetStringMinimumBoundedRectangle(fragmentIndex, minimumBoundedRectangleIndex, dimensionIndex, dataType);
return ((T)(object)startStr, (T)(object)endStr);
}
ThrowHelpers.ThrowTypeNotSupported();
ThrowHelpers.ThrowTypeMismatch(dataType);
return default;
}
ValidateDomainType<T>(dataType);
Expand Down Expand Up @@ -450,13 +450,13 @@ public ulong GetMinimumBoundedRectangleCount(uint fragmentIndex)
DataType dataType = GetDimensionType(fragmentIndex, dimensionName);
if (RuntimeHelpers.IsReferenceOrContainsReferences<T>())
{
if (typeof(T) == typeof(string))
if (typeof(T) == typeof(string) && EnumUtil.IsStringType(dataType))
{
(string startStr, string endStr) =
GetStringMinimumBoundedRectangle(fragmentIndex, minimumBoundedRectangleIndex, dimensionName, dataType);
return ((T)(object)startStr, (T)(object)endStr);
}
ThrowHelpers.ThrowTypeNotSupported();
ThrowHelpers.ThrowTypeMismatch(dataType);
return default;
}
ValidateDomainType<T>(dataType);
Expand Down Expand Up @@ -536,12 +536,12 @@ public ulong GetMinimumBoundedRectangleCount(uint fragmentIndex)
DataType dataType = GetDimensionType(fragmentIndex, dimensionIndex);
if (RuntimeHelpers.IsReferenceOrContainsReferences<T>())
{
if (typeof(T) == typeof(string))
if (typeof(T) == typeof(string) && EnumUtil.IsStringType(dataType))
{
(string startStr, string endStr) = GetStringNonEmptyDomain(fragmentIndex, dimensionIndex, dataType);
return ((T)(object)startStr, (T)(object)endStr);
}
ThrowHelpers.ThrowTypeNotSupported();
ThrowHelpers.ThrowTypeMismatch(dataType);
return default;
}
ValidateDomainType<T>(dataType);
Expand Down Expand Up @@ -574,12 +574,12 @@ public ulong GetMinimumBoundedRectangleCount(uint fragmentIndex)
DataType dataType = GetDimensionType(fragmentIndex, dimensionName);
if (RuntimeHelpers.IsReferenceOrContainsReferences<T>())
{
if (typeof(T) == typeof(string))
if (typeof(T) == typeof(string) && EnumUtil.IsStringType(dataType))
{
(string startStr, string endStr) = GetStringNonEmptyDomain(fragmentIndex, dimensionName, dataType);
return ((T)(object)startStr, (T)(object)endStr);
}
ThrowHelpers.ThrowTypeNotSupported();
ThrowHelpers.ThrowTypeMismatch(dataType);
return default;
}
ValidateDomainType<T>(dataType);
Expand Down

0 comments on commit 5ccc03f

Please sign in to comment.