Example #1
0
 public RowParserResult <T> Parse(TRow row)
 {
     try
     {
         return(_parser(row));
     }
     catch (Exception ex)
     {
         return(RowParserResult.Failed <T>(ex));
     }
 }
Example #2
0
        private static RowParser <T, IDataRecord> Simple <T>(int col, Func <IDataRecord, T> f)
        {
            return(new RowParser <T, IDataRecord>(row =>
            {
                if (row.IsDBNull(col))
                {
                    return RowParserResult.Failed <T>(UnexpectedNullFieldException.UnexpectedNull);
                }

                return RowParserResult.Successful(f(row));
            }));
        }
Example #3
0
        public static RowParser <IMaybe <T>, IDataRecord> Optional <T>(RowParser <T, IDataRecord> other)
        {
            return(new RowParser <IMaybe <T>, IDataRecord>(row =>
            {
                return other.Parse(row).Map(Maybe.Just).Recover(ex =>
                {
                    if (ex == UnexpectedNullFieldException.UnexpectedNull)
                    {
                        return RowParserResult.Successful(Maybe.Nothing <T>());
                    }

                    return RowParserResult.Failed <IMaybe <T> >(ex);
                });
            }));
        }