Example #1
0
        /// <summary>
        /// Resolve the given <paramref name="criteria"/> into a
        /// <see cref="IDataReaderMapper{T}"/> object.
        /// </summary>
        public static IDataReaderMapper <T> Resolve <T>(this ICriteria criteria,
                                                        string prefix)
        {
            object obj;
            string hash = prefix + ":" + criteria.Fields.Join(":");

            if (mappers_.TryGetValue(hash, out obj))
            {
                return((IDataReaderMapper <T>)obj);
            }

            var builder = new DataReaderMapperBuilder <T>();

            foreach (var field in criteria.Fields)
            {
                string map = criteria.GetFieldMap(field);
                builder.Map(field, map);
            }
            IDataReaderMapper <T> mapper = builder.Build();

            mappers_.Add(hash, mapper);
            return(mapper);
        }