コード例 #1
0
        private static IReadOnlyDictionary <string, string> GetPropertyNames <TModel>(IDataRecord reader, CasheConfig casheConfig)
            where TModel : class, new()
        {
            var columnNames = GetUpperCaseColumnNames(reader);
            Dictionary <string, string> columnNamesDic = casheConfig.useStandardCodeStyleForMembers ?
                                                         columnNames.ToDictionary(p => p.Replace("_", ""), p => p) :
                                                         columnNames.ToDictionary(p => p, p => p);

            var properties = casheConfig.ignoreMembers.IsNullOrEmpty()
                ? typeof(TModel).GetProperties()
                : typeof(TModel).GetProperties().Where(pi => !casheConfig.ignoreMembers.Contains(pi.Name));

            var piDic = properties.Where(pi => columnNamesDic.ContainsKey(pi.Name.ToUpper())).ToDictionary(pi => pi.Name, pi => columnNamesDic[pi.Name.ToUpper()]);

            if (!casheConfig.bindings.IsNullOrEmpty())
            {
                foreach (var b in casheConfig.bindings)
                {
                    piDic[b.Key] = b.Value;
                }
            }

            return(new ReadOnlyDictionary <string, string>(piDic));
        }
コード例 #2
0
 internal static Expression <Func <IDataRecord, TModel> > Map <TModel>(this IDataRecord reader, CasheConfig casheConfig)
     where TModel : class, new()
 {
     return(Map <TModel>(GetPropertyNames <TModel>(reader, casheConfig)));
 }