Ejemplo n.º 1
0
        protected void BindArray(ICommandContext ctx, object arrayArg)
        {
            if (arrayArg == null)
            {
                return;
            }
            object[] array  = arrayArg as object[];
            int      length = array.Length;

            if (length == 0)
            {
                ThrowBindOrEmbeddedParameterEmptyListException();
            }
            Type type = null;

            for (int i = 0; i < length; ++i)
            {
                Object currentElement = array[i];
                if (currentElement != null)
                {
                    type = currentElement.GetType();
                    break;
                }
            }
            if (type == null)
            {
                ThrowBindOrEmbeddedParameterNullOnlyListException();
            }
            ctx.AddSql("(");
            int bindCount = 0;

            for (int i = 0; i < length; ++i)
            {
                Object currentElement = array[i];
                if (currentElement != null)
                {
                    ++bindCount;
                    if (bindCount == 1)                  // FirstElement!
                    {
                        ctx.AddSql(currentElement, type, _expression + bindCount);
                    }
                    else
                    {
                        ctx.AppendSql(currentElement, type, _expression + bindCount);
                    }
                }
            }
            ctx.AddSql(")");
        }