Exemple #1
0
        public static void Initialize(Action <DbDataReaderMapperConfiguration> configuration)
        {
            var configuration2 = new DbDataReaderMapperConfiguration();

            configuration.Invoke(configuration2);

            Initialize(configuration2);
        }
Exemple #2
0
        private static List <DbDataReaderMapperItem> GetItemList(DbDataReaderMapperConfiguration configuration)
        {
            var ttype      = typeof(TResultItem);
            int code       = 1;
            var resultList = new List <DbDataReaderMapperItem>();

            if (configuration.UseProperties)
            {
                foreach (var propertyInfo in ttype.GetRuntimeProperties())
                {
                    if (ValidateProperty(propertyInfo))
                    {
                        ProcessType(propertyInfo.PropertyType, out bool isNullable, out MethodInfo? dbDataReader_GetValue_MethodInfo);
                        if (dbDataReader_GetValue_MethodInfo != null)
                        {
                            resultList.Add(new DbDataReaderMapperProperty(code, isNullable, dbDataReader_GetValue_MethodInfo, propertyInfo));
                            code++;
                        }
                    }
                }
            }
            if (configuration.UseFields)
            {
                foreach (var fieldInfo in ttype.GetRuntimeFields())
                {
                    if (ValidateField(fieldInfo))
                    {
                        ProcessType(fieldInfo.FieldType, out bool isNullable, out MethodInfo? dbDataReader_GetValue_MethodInfo);
                        if (dbDataReader_GetValue_MethodInfo != null)
                        {
                            resultList.Add(new DbDataReaderMapperField(code, isNullable, dbDataReader_GetValue_MethodInfo, fieldInfo));
                            code++;
                        }
                    }
                }
            }

            return(resultList);
        }
Exemple #3
0
        private static Expression BuildInitSwitch(ParameterExpression dbDataReader, ParameterExpression i, Expression readerMap, List <DbDataReaderMapperItem> itemList, DbDataReaderMapperConfiguration configuration)
        {
            if (itemList.Count <= 0)
            {
                return(Expression.Empty());
            }

            var breakLabel = Expression.Label();

            var switchCaseList = new List <SwitchCase>();

            foreach (var item in itemList)
            {
                switchCaseList.Add(
                    Expression.SwitchCase(
                        Expression.Block(
                            Expression.Assign(
                                Expression.ArrayAccess(readerMap, i),
                                Expression.Constant(item.Code)
                                ),
                            Expression.Break(breakLabel)
                            ),
                        Expression.Constant(configuration.CaseSensitive ? item.ItemName : item.ItemName.ToUpper())
                        )
                    );
            }

            var switchExpression =
                Expression.Block(
                    Expression.Switch(
                        Call(null, DbDataReaderMapper_GetName, dbDataReader, i, Expression.Constant(configuration.CaseSensitive)),
                        switchCaseList.ToArray()
                        ),
                    Expression.Label(breakLabel)
                    );

            return(switchExpression);
        }