예제 #1
0
        /// <summary>
        /// Appends a <see cref="Argument"/> to the <see cref="CommandInfo"/> object.
        /// </summary>
        /// <param name="command">The command.</param>
        /// <param name="memberName">Name of the member.</param>
        /// <param name="dataType">The data-type.</param>
        /// <returns>The <see cref="Argument"/> object.</returns>
        public static Argument WithParameter(this CommandInfo command, string memberName, Type dataType)
        {
            var argument = new Argument(memberName, dataType)
            {
                Position = command.Count
            };

            command.Add(argument);
            return(argument);
        }
예제 #2
0
        /// <summary>
        /// Appends a <see cref="Argument"/> to the <see cref="CommandInfo"/> object.
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="command">The command.</param>
        /// <param name="member">The member name.</param>
        /// <returns>The <see cref="Argument"/> object.</returns>
        public static Argument <T> WithParameter <T>(this CommandInfo <T> command, Expression <Func <T, object> > member)
        {
            var argument = new Argument <T>
            {
                Position = command.Count,
                Default  = default(T)
            };

            if (member.Body is UnaryExpression ue)
            {
                var m = (ue.Operand as MemberExpression);
                argument.MemberName = m.Member.Name;
                argument.DataType   = (m.Member.MemberType == MemberTypes.Field) ? ((FieldInfo)m.Member).FieldType : ((PropertyInfo)m.Member).PropertyType;
            }
            else if (member.Body is MemberExpression me)
            {
                argument.MemberName = me.Member.Name;
                argument.DataType   = (me.Member.MemberType == MemberTypes.Field) ? ((FieldInfo)me.Member).FieldType : ((PropertyInfo)me.Member).PropertyType;
            }

            command.Add(argument);
            return(argument);
        }