示例#1
0
 public RowParserResult <T> Parse(TRow row)
 {
     try
     {
         return(_parser(row));
     }
     catch (Exception ex)
     {
         return(RowParserResult.Failed <T>(ex));
     }
 }
示例#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));
            }));
        }
示例#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);
                });
            }));
        }
示例#4
0
 public static RowParser <T, IDataRecord> Named <T>(string name, Func <int, RowParser <T, IDataRecord> > byIndexParser)
 {
     return(new RowParser <int, IDataRecord>(row => RowParserResult.Successful(row.GetOrdinal(name)))
            .FlatMap(byIndexParser));
 }