Skip to content
Merged
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
16 changes: 16 additions & 0 deletions src/DbfDataReader/AsciiFieldParser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,33 +13,49 @@ internal static class AsciiFieldParser
public static bool TryParse(ReadOnlySpan<byte> bytes, NumberStyles styles, NumberFormatInfo format,
out decimal value)
{
#if NET8_0_OR_GREATER
return decimal.TryParse(bytes, styles, format, out value);
#else
Span<char> chars = stackalloc char[bytes.Length];
Decode(bytes, chars);
return decimal.TryParse(chars, styles, format, out value);
#endif
}

public static bool TryParse(ReadOnlySpan<byte> bytes, NumberStyles styles, NumberFormatInfo format,
out int value)
{
#if NET8_0_OR_GREATER
return int.TryParse(bytes, styles, format, out value);
#else
Span<char> chars = stackalloc char[bytes.Length];
Decode(bytes, chars);
return int.TryParse(chars, styles, format, out value);
#endif
}

public static bool TryParse(ReadOnlySpan<byte> bytes, NumberStyles styles, NumberFormatInfo format,
out long value)
{
#if NET8_0_OR_GREATER
return long.TryParse(bytes, styles, format, out value);
#else
Span<char> chars = stackalloc char[bytes.Length];
Decode(bytes, chars);
return long.TryParse(chars, styles, format, out value);
#endif
}

public static bool TryParse(ReadOnlySpan<byte> bytes, NumberStyles styles, NumberFormatInfo format,
out float value)
{
#if NET8_0_OR_GREATER
return float.TryParse(bytes, styles, format, out value);
#else
Span<char> chars = stackalloc char[bytes.Length];
Decode(bytes, chars);
return float.TryParse(chars, styles, format, out value);
#endif
}

public static bool TryParseDate(ReadOnlySpan<byte> bytes, string dateFormat, out DateTime value)
Expand Down