public object GetValue(RequestScope request, ResultProperty mapping, ref IDataReader reader, object keys)
        {
            IMappedStatement mappedStatement = request.MappedStatement.SqlMap.GetMappedStatement(mapping.Select);

            reader = DataReaderTransformer.Transform(reader, request.Session.DataSource.DbProvider);
            Type[] genericArguments = mapping.MemberType.GetGenericArguments();
            typeof(IList <>).MakeGenericType(genericArguments);
            Type type2 = mapping.MemberType.GetGenericArguments()[0];

            MethodInfo[] methods = mappedStatement.GetType().GetMethods(BindingFlags.InvokeMethod | BindingFlags.Public | BindingFlags.Instance);
            MethodInfo   info    = null;

            foreach (MethodInfo info2 in methods)
            {
                if ((info2.IsGenericMethod && (info2.Name == "ExecuteQueryForList")) && (info2.GetParameters().Length == 2))
                {
                    info = info2;
                    break;
                }
            }
            MethodInfo info3 = info.MakeGenericMethod(new Type[] { type2 });

            object[] parameters = new object[] { request.Session, keys };
            return(info3.Invoke(mappedStatement, parameters));
        }
Beispiel #2
0
        /// <summary>
        /// Gets the value of an argument constructor.
        /// </summary>
        /// <param name="request">The current <see cref="RequestScope"/>.</param>
        /// <param name="mapping">The <see cref="ResultProperty"/> with the argument infos.</param>
        /// <param name="reader">The current <see cref="IDataReader"/>.</param>
        /// <param name="keys">The keys</param>
        /// <returns>The paremeter value.</returns>
        public object GetValue(RequestScope request, ResultProperty mapping,
                               ref IDataReader reader, object keys)
        {
            // Get the select statement
            IMappedStatement selectStatement = request.MappedStatement.ModelStore.GetMappedStatement(mapping.Select);

            reader = DataReaderTransformer.Transform(reader, request.Session.SessionFactory.DataSource.DbProvider);

            //Type[] typeArgs = mapping.MemberType.GetGenericArguments();
            //Type genericList = typeof(IList<>);
            //Type constructedType = genericList.MakeGenericType(typeArgs);
            Type elementType = mapping.MemberType.GetGenericArguments()[0];

            Type mappedStatementType = selectStatement.GetType();

            //Type[] typeArguments = { typeof(ISession), typeof(object) };

            MethodInfo[] mis = mappedStatementType.GetMethods(BindingFlags.InvokeMethod | BindingFlags.Public | BindingFlags.Instance);
            MethodInfo   mi  = null;

            for (int i = 0; i < mis.Length; i++)
            {
                if (mis[i].IsGenericMethod &&
                    mis[i].Name == "ExecuteQueryForList" &&
                    mis[i].GetParameters().Length == 2)
                {
                    mi = mis[i];
                    break;
                }
            }

            MethodInfo miConstructed = mi.MakeGenericMethod(elementType);

            // Invoke the method.
            object[] args   = { request.Session, keys };
            object   values = miConstructed.Invoke(selectStatement, args);

            return(values);
        }