using Npgsql; namespace NpgsqlRest.Extensions; public static class Ext { public static T Get(this NpgsqlDataReader reader, int ordinal) { var value = reader[ordinal]; if (value == DBNull.Value) { return default!; } // strange bug single char representing as string on older pg versions when using functions if (typeof(T) == typeof(char) && value.GetType() == typeof(string)) { if (value is null) { return default!; } object c = ((string)value)[0]; return (T)c; } return (T)value; } public static T GetEnum(this string? value) where T : struct { Enum.TryParse(value, true, out var result); // return the first enum (Other) when no match return result; } }