Skip to content

Add uint -> int casts #6

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 12 additions & 6 deletions FeatherDotNet/Impl/ColumnSpec.cs
Original file line number Diff line number Diff line change
Expand Up @@ -312,13 +312,15 @@ public static bool CanMapTo(this ColumnType fromType, Type toType, string[] cate
return toType == typeof(long) || toType == typeof(long?) || toType == typeof(int) || toType == typeof(int?) || toType == typeof(short) || toType == typeof(short?) || toType == typeof(float) || toType == typeof(float?) || toType == typeof(double) || toType == typeof(double?);

case ColumnType.Uint16:
return toType == typeof(ulong) || toType == typeof(ulong?) || toType == typeof(uint) || toType == typeof(uint?) || toType == typeof(ushort) || toType == typeof(ushort?) || toType == typeof(float) || toType == typeof(float?) || toType == typeof(double) || toType == typeof(double?);
return toType == typeof(ulong) || toType == typeof(ulong?) || toType == typeof(uint) || toType == typeof(uint?) || toType == typeof(ushort) || toType == typeof(ushort?) || toType == typeof(float) || toType == typeof(float?) || toType == typeof(double) || toType == typeof(double?) ||
toType == typeof(long) || toType == typeof(long?) || toType == typeof(int) || toType == typeof(int?);

case ColumnType.Int32:
return toType == typeof(long) || toType == typeof(long?) || toType == typeof(int) || toType == typeof(int?) || toType == typeof(float) || toType == typeof(float?) || toType == typeof(double) || toType == typeof(double?);

case ColumnType.Uint32:
return toType == typeof(ulong) || toType == typeof(ulong?) || toType == typeof(uint) || toType == typeof(uint?) || toType == typeof(float) || toType == typeof(float?) || toType == typeof(double) || toType == typeof(double?);
return toType == typeof(ulong) || toType == typeof(ulong?) || toType == typeof(uint) || toType == typeof(uint?) || toType == typeof(float) || toType == typeof(float?) || toType == typeof(double) || toType == typeof(double?) ||
toType == typeof(long) || toType == typeof(long?);

case ColumnType.Int64:
return toType == typeof(long) || toType == typeof(long?) || toType == typeof(float) || toType == typeof(float?) || toType == typeof(double) || toType == typeof(double?);
Expand All @@ -330,7 +332,8 @@ public static bool CanMapTo(this ColumnType fromType, Type toType, string[] cate
return toType == typeof(sbyte) || toType == typeof(sbyte?) || toType == typeof(long) || toType == typeof(long?) || toType == typeof(int) || toType == typeof(int?) || toType == typeof(short) || toType == typeof(short?) || toType == typeof(float) || toType == typeof(float?) || toType == typeof(double) || toType == typeof(double?);

case ColumnType.Uint8:
return toType == typeof(byte) || toType == typeof(byte?) || toType == typeof(ulong) || toType == typeof(ulong?) || toType == typeof(uint) || toType == typeof(uint?) || toType == typeof(ushort) || toType == typeof(ushort?) || toType == typeof(float) || toType == typeof(float?) || toType == typeof(double) || toType == typeof(double?);
return toType == typeof(byte) || toType == typeof(byte?) || toType == typeof(ulong) || toType == typeof(ulong?) || toType == typeof(uint) || toType == typeof(uint?) || toType == typeof(ushort) || toType == typeof(ushort?) || toType == typeof(float) || toType == typeof(float?) || toType == typeof(double) || toType == typeof(double?) ||
toType == typeof(long) || toType == typeof(long?) || toType == typeof(int) || toType == typeof(int?) || toType == typeof(short) || toType == typeof(short?);

case ColumnType.NullableBool:
return toType == typeof(bool?);
Expand All @@ -352,13 +355,15 @@ public static bool CanMapTo(this ColumnType fromType, Type toType, string[] cate
return toType == typeof(long?) || toType == typeof(int?) || toType == typeof(short?) || toType == typeof(float?) || toType == typeof(double?);

case ColumnType.NullableUint16:
return toType == typeof(ulong?) || toType == typeof(uint?) || toType == typeof(ushort?) || toType == typeof(float?) || toType == typeof(double?);
return toType == typeof(ulong?) || toType == typeof(uint?) || toType == typeof(ushort?) || toType == typeof(float?) || toType == typeof(double?) ||
toType == typeof(long?) || toType == typeof(int?);

case ColumnType.NullableInt32:
return toType == typeof(long?) || toType == typeof(int?) || toType == typeof(float?) || toType == typeof(double?);

case ColumnType.NullableUint32:
return toType == typeof(ulong?) || toType == typeof(uint?) || toType == typeof(float?) || toType == typeof(double?);
return toType == typeof(ulong?) || toType == typeof(uint?) || toType == typeof(float?) || toType == typeof(double?) ||
toType == typeof(long?);

case ColumnType.NullableInt64:
return toType == typeof(long?) || toType == typeof(float?) || toType == typeof(double?);
Expand All @@ -370,7 +375,8 @@ public static bool CanMapTo(this ColumnType fromType, Type toType, string[] cate
return toType == typeof(sbyte?) || toType == typeof(long?) || toType == typeof(int?) || toType == typeof(short?) || toType == typeof(float) || toType == typeof(float?) || toType == typeof(double) || toType == typeof(double?);

case ColumnType.NullableUint8:
return toType == typeof(byte?) || toType == typeof(ulong?) || toType == typeof(uint?) || toType == typeof(ushort?) || toType == typeof(float) || toType == typeof(float?) || toType == typeof(double) || toType == typeof(double?);
return toType == typeof(byte?) || toType == typeof(ulong?) || toType == typeof(uint?) || toType == typeof(ushort?) || toType == typeof(float) || toType == typeof(float?) || toType == typeof(double) || toType == typeof(double?) ||
toType == typeof(long?) || toType == typeof(int?) || toType == typeof(short?);

case ColumnType.String:
case ColumnType.NullableString:
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ See the [test project](https://github.com/kevin-montrose/FeatherDotNet/FeatherDo
## Type Mappings

Integer types can be freely converted provided the underlying type is at least as large as the .NET type (an `Int16` can be mapped to an `int`,
but and `Int64` may not be mapped to a `int`) and the signedness is the same (a `UInt16` cannot be mapped to an `int`).
but `Int64` may not be mapped to a `int`) and respects signedness (a `UInt16` can be mapped into `int`, whereas `Int16` can't be mapped into `uint` due to possible loss of sign).

For floating point values, `float` and `double` are supported target types (`decimal` is not). All integer types can be converted to `float` or `double`.
If the underlying type is a `Double` it cannot be converted to a `float`, but `Single`s can be converted to `double`s.
Expand Down