示例#1
0
    public static System.Object ElementAtOrDefault(this System.Collections.IEnumerable collection, int index)
    {
        var enumerator = collection.GetEnumerator();
        int j          = 0;

        for (; enumerator.MoveNext(); j++)
        {
            if (j == index)
            {
                break;
            }
        }

        System.Object element = (j == index)
            ? enumerator.Current
            : default(System.Object);

        var disposable = enumerator as System.IDisposable;

        if (disposable != null)
        {
            disposable.Dispose();
        }

        return(element);
    }
示例#2
0
        public static void NotNullOrEmpty([ValidatedNotNull] System.Collections.IEnumerable values, string parameterName)
        {
            // To the guy that is doing random code cleaning:
            // Consider the performance when changing the code to delegate to NotNull.
            // In general do not chain call to another function, check first and return as earlier as possible.
            if (values == null)
            {
                throw new ArgumentNullException(parameterName);
            }

            ICollection collection = values as ICollection;

            if (collection != null)
            {
                if (collection.Count > 0)
                {
                    return;
                }

                throw new ArgumentException(Format(Strings.Argument_EmptyArray, parameterName), parameterName);
            }

            IEnumerator enumerator = values.GetEnumerator();

            using (enumerator as IDisposable)
            {
                if (enumerator.MoveNext())
                {
                    return;
                }
            }

            throw new ArgumentException(Format(Strings.Argument_EmptyArray, parameterName), parameterName);
        }
示例#3
0
        /// <summary>
        /// When overridden in a derived class, binds data from the data source to the control.
        /// </summary>
        /// <param name="data">The <see cref="T:System.Collections.IEnumerable"></see> list of data returned from a <see cref="M:System.Web.UI.WebControls.DataBoundControl.PerformSelect"></see> method call.</param>
        protected override void PerformDataBinding(System.Collections.IEnumerable data)
        {
            if (data == null)
            {
                return;
            }

            // get the next data item
            IEnumerator e = data.GetEnumerator();

            while (e.MoveNext())
            {
                // get the text item if specified
                if (!string.IsNullOrEmpty(DataTextField))
                {
                    this.Text = DataBinder.GetPropertyValue(e.Current, DataTextField);
                }

                // get the value item if specified
                if (!string.IsNullOrEmpty(DataValueField))
                {
                    this.Value = DataBinder.GetPropertyValue(e.Current, DataValueField);
                }

                // we only do the first item
                break;
            }
        }
示例#4
0
        /// <summary>
        /// Called when the ItemsSource changes to auto populate the GridView columns
        /// with reflection information on the first element of the ItemsSource.
        /// </summary>
        /// <param name="newValue">
        /// The new ItemsSource.
        /// This is used just to fetch .the first collection element.
        /// </param>
        internal void PopulateColumns(System.Collections.IEnumerable newValue)
        {
            if (newValue == null)
            {
                return; // No elements, so we can't populate
            }

            IEnumerator newValueEnumerator = newValue.GetEnumerator();

            if (!newValueEnumerator.MoveNext())
            {
                return; // No first element, so we can't populate
            }

            object first = newValueEnumerator.Current;

            if (first == null)
            {
                return;
            }

            Debug.Assert(this.AvailableColumns.Count == 0, "AvailabeColumns should be empty at this point");

            PropertyDescriptorCollection properties = TypeDescriptor.GetProperties(first);

            foreach (PropertyDescriptor property in properties)
            {
                UIPropertyGroupDescription dataDescription = new UIPropertyGroupDescription(property.Name, property.Name, property.PropertyType);
                InnerListColumn            column          = new InnerListColumn(dataDescription);
                this.AvailableColumns.Add(column);
            }
        }
示例#5
0
        public static IEnumerable Shuffle(System.Collections.IEnumerable enumerable)
        {
            if (enumerable == null)
            {
                return(null);
            }

            ArrayList   list = new ArrayList();
            IEnumerator en   = enumerable.GetEnumerator();

            while (en.MoveNext())
            {
                list.Add(en.Current);
            }

            for (int i = 0; i < list.Count; i++)
            {
                int r = random.Next(0, list.Count);

                object tmp = list[i];
                list[i] = list[r];
                list[r] = tmp;
            }

            return(list);
        }
        protected override int CreateChildControls(System.Collections.IEnumerable dataSource, bool dataBinding)
        {
            int itemCount = 0;

            if (dataSource != null)
            {
                Controls.Clear();

                Panel PanelHead = new Panel();
                PanelHead.Attributes.Add("class", "widget-indicators-bar");
                Controls.Add(PanelHead);

                HyperLink HLnkTitulo = new HyperLink();
                HLnkTitulo.Attributes.Add("title", "Opciones");
                HLnkTitulo.Attributes.Add("class", "widget-indicators-trigger");
                HLnkTitulo.Text = "Indicadores";

                PanelHead.Controls.Add(HLnkTitulo);

                Panel PanelContent = new Panel();
                PanelContent.Attributes.Add("class", "widget-indicators-content");
                Controls.Add(PanelContent);

                HtmlGenericControl HtmlList = new HtmlGenericControl("ul");
                HtmlList.Attributes.Add("class", "widget-indicators-main-list");
                PanelContent.Controls.Add(HtmlList);

                if (dataBinding)
                {
                    IEnumerator e = dataSource.GetEnumerator();
                    while (e.MoveNext())
                    {
                        DataRowView datarow = (DataRowView)e.Current;

                        HtmlGenericControl HtmlItem = new HtmlGenericControl("li");
                        HtmlItem.Attributes.Add("class", "widget-indicator-item True");
                        HtmlItem.Attributes.Add("indicatorid", datarow["INDICATORID"].ToString());

                        Image imgDelete = new Image();
                        imgDelete.ImageUrl = Page.ClientScript.GetWebResourceUrl(this.GetType(), "KPIServerControls.images.notification_error.png");
                        imgDelete.Attributes.Add("class", "delKpi");

                        Label lbNombre = new Label();
                        lbNombre.Text = datarow["TITULO"].ToString();
                        lbNombre.Attributes.Add("class", "item");

                        HtmlItem.Controls.Add(imgDelete);
                        HtmlItem.Controls.Add(lbNombre);

                        HtmlList.Controls.Add(HtmlItem);
                        itemCount++;
                    }
                }
            }
            return(itemCount);
        }
示例#7
0
        IEnumerator <Component> IEnumerable <Component> .GetEnumerator()
        {
            System.Collections.IEnumerable enumer   = this as System.Collections.IEnumerable;
            System.Collections.IEnumerator iterator = enumer.GetEnumerator();

            while (iterator.MoveNext())
            {
                yield return(iterator.Current as Component);
            }
        }
示例#8
0
        IEnumerator <SaldoAwal> IEnumerable <SaldoAwal> .GetEnumerator()
        {
            System.Collections.IEnumerable enumer   = this as System.Collections.IEnumerable;
            System.Collections.IEnumerator iterator = enumer.GetEnumerator();

            while (iterator.MoveNext())
            {
                yield return(iterator.Current as SaldoAwal);
            }
        }
示例#9
0
        IEnumerator <RadMenuDataSource> IEnumerable <RadMenuDataSource> .GetEnumerator()
        {
            System.Collections.IEnumerable enumer   = this as System.Collections.IEnumerable;
            System.Collections.IEnumerator iterator = enumer.GetEnumerator();

            while (iterator.MoveNext())
            {
                yield return(iterator.Current as RadMenuDataSource);
            }
        }
示例#10
0
        IEnumerator <MonthlyBalance> IEnumerable <MonthlyBalance> .GetEnumerator()
        {
            System.Collections.IEnumerable enumer   = this as System.Collections.IEnumerable;
            System.Collections.IEnumerator iterator = enumer.GetEnumerator();

            while (iterator.MoveNext())
            {
                yield return(iterator.Current as MonthlyBalance);
            }
        }
示例#11
0
        IEnumerator <MpiPayplanMapping> IEnumerable <MpiPayplanMapping> .GetEnumerator()
        {
            System.Collections.IEnumerable enumer   = this as System.Collections.IEnumerable;
            System.Collections.IEnumerator iterator = enumer.GetEnumerator();

            while (iterator.MoveNext())
            {
                yield return(iterator.Current as MpiPayplanMapping);
            }
        }
示例#12
0
        IEnumerator <VwFundPrices> IEnumerable <VwFundPrices> .GetEnumerator()
        {
            System.Collections.IEnumerable enumer   = this as System.Collections.IEnumerable;
            System.Collections.IEnumerator iterator = enumer.GetEnumerator();

            while (iterator.MoveNext())
            {
                yield return(iterator.Current as VwFundPrices);
            }
        }
示例#13
0
        IEnumerator <KasDataSourceComboBox> IEnumerable <KasDataSourceComboBox> .GetEnumerator()
        {
            System.Collections.IEnumerable enumer   = this as System.Collections.IEnumerable;
            System.Collections.IEnumerator iterator = enumer.GetEnumerator();

            while (iterator.MoveNext())
            {
                yield return(iterator.Current as KasDataSourceComboBox);
            }
        }
示例#14
0
        IEnumerator <LevelMA> IEnumerable <LevelMA> .GetEnumerator()
        {
            System.Collections.IEnumerable enumer   = this as System.Collections.IEnumerable;
            System.Collections.IEnumerator iterator = enumer.GetEnumerator();

            while (iterator.MoveNext())
            {
                yield return(iterator.Current as LevelMA);
            }
        }
示例#15
0
        IEnumerator <AppUserGroupProgram> IEnumerable <AppUserGroupProgram> .GetEnumerator()
        {
            System.Collections.IEnumerable enumer   = this as System.Collections.IEnumerable;
            System.Collections.IEnumerator iterator = enumer.GetEnumerator();

            while (iterator.MoveNext())
            {
                yield return(iterator.Current as AppUserGroupProgram);
            }
        }
示例#16
0
        IEnumerator <AutoNumbering> IEnumerable <AutoNumbering> .GetEnumerator()
        {
            System.Collections.IEnumerable enumer   = this as System.Collections.IEnumerable;
            System.Collections.IEnumerator iterator = enumer.GetEnumerator();

            while (iterator.MoveNext())
            {
                yield return(iterator.Current as AutoNumbering);
            }
        }
示例#17
0
        IEnumerator <MpiSyncKunjungan> IEnumerable <MpiSyncKunjungan> .GetEnumerator()
        {
            System.Collections.IEnumerable enumer   = this as System.Collections.IEnumerable;
            System.Collections.IEnumerator iterator = enumer.GetEnumerator();

            while (iterator.MoveNext())
            {
                yield return(iterator.Current as MpiSyncKunjungan);
            }
        }
示例#18
0
        IEnumerator <TransaksiBKU> IEnumerable <TransaksiBKU> .GetEnumerator()
        {
            System.Collections.IEnumerable enumer   = this as System.Collections.IEnumerable;
            System.Collections.IEnumerator iterator = enumer.GetEnumerator();

            while (iterator.MoveNext())
            {
                yield return(iterator.Current as TransaksiBKU);
            }
        }
示例#19
0
        IEnumerator <PeriodeAnggaran> IEnumerable <PeriodeAnggaran> .GetEnumerator()
        {
            System.Collections.IEnumerable enumer   = this as System.Collections.IEnumerable;
            System.Collections.IEnumerator iterator = enumer.GetEnumerator();

            while (iterator.MoveNext())
            {
                yield return(iterator.Current as PeriodeAnggaran);
            }
        }
示例#20
0
        public static List <T> Enumerable2List <T>(System.Collections.IEnumerable e)
        {
            var list = new List <T>();
            var i    = e.GetEnumerator();

            while (i.MoveNext())
            {
                list.Add((T)i.Current);
            }
            return(list);
        }
示例#21
0
 public static void IsNotEmpty(System.Collections.IEnumerable collection)
 {
     if (collection != null)
     {
         Fail("IsNotEmpty: collection is null");
     }
     if (!collection.GetEnumerator().MoveNext())
     {
         Fail("IsNotEmpty: collection is empty");
     }
 }
        protected override int CreateChildControls(System.Collections.IEnumerable dataSource, bool dataBinding)
        {
            int itemCount = 0;

            if (dataSource != null)
            {
                Controls.Clear();

                Panel PanelHead = new Panel();
                PanelHead.Attributes.Add("class", "widget-dimensions-bar marginleft");
                Controls.Add(PanelHead);

                Label LabelTitle = new Label();
                LabelTitle.Attributes.Add("class", "title");
                if (!string.IsNullOrEmpty(Text))
                {
                    LabelTitle.Text = Text;
                }
                else
                {
                    LabelTitle.Text = "Dimensión";
                }

                Panel PanelContent = new Panel();
                PanelContent.Attributes.Add("class", "widget-menu-list");

                PanelHead.Controls.Add(LabelTitle);
                PanelHead.Controls.Add(PanelContent);

                if (dataBinding)
                {
                    IEnumerator e = dataSource.GetEnumerator();
                    while (e.MoveNext())
                    {
                        DataRowView datarow = (DataRowView)e.Current;

                        Panel PanelItem = new Panel();
                        PanelItem.Attributes.Add("class", "widget-menu-item dimensions-item");
                        PanelItem.Attributes.Add("valor", datarow["CODIGO"].ToString());

                        Label LabelNombre = new Label();
                        LabelNombre.Text = datarow["DESCRIPCION"].ToString();

                        PanelItem.Controls.Add(LabelNombre);
                        PanelContent.Controls.Add(PanelItem);

                        itemCount++;
                    }
                }
            }
            return(itemCount);
        }
示例#23
0
        /// <summary>
        /// Will use insert adapter and comparer and IFilter if they are set. Observes the list for changes.
        /// </summary>
        /// <param name="items"></param>
        public void InsertSorted(System.Collections.IEnumerable items)
        {
            if (items is INotifyCollectionChanged)
            {
                ((INotifyCollectionChanged)items).CollectionChanged += items_CollectionChanged;
            }

            IEnumerator i = items.GetEnumerator();

            while (i.MoveNext())
            {
                InsertSorted((T)i.Current);
            }
        }
示例#24
0
        internal static List <T> ToListNonGeneric <T>(System.Collections.IEnumerable sequence)
        {
            Assert.NotNull(sequence);

            var list       = new List <T>();
            var enumerator = sequence.GetEnumerator();

            while (enumerator.MoveNext())
            {
                list.Add((T)enumerator.Current);
            }

            return(list);
        }
示例#25
0
        protected override int CreateChildControls(System.Collections.IEnumerable dataSource, bool dataBinding)
        {
            int itemCount = 0;

            if (dataSource != null)
            {
                Controls.Clear();

                Panel PanelHead = new Panel();
                PanelHead.Attributes.Add("class", "widget-graphics-bar marginright");
                Controls.Add(PanelHead);

                Image ImgTitle = new Image();
                ImgTitle.Attributes.Add("class", "principal");
                ImgTitle.ImageUrl = GetImageUrl(Valor);

                Panel PanelContent = new Panel();
                PanelContent.Attributes.Add("class", "widget-menu-list graphics");

                PanelHead.Controls.Add(ImgTitle);
                PanelHead.Controls.Add(PanelContent);

                if (dataBinding)
                {
                    IEnumerator e = dataSource.GetEnumerator();
                    while (e.MoveNext())
                    {
                        DataRowView datarow = (DataRowView)e.Current;

                        Panel PanelItem = new Panel();
                        PanelItem.Attributes.Add("class", "widget-menu-item graphics-item");
                        PanelItem.Attributes.Add("valor", datarow["CODIGO"].ToString());

                        Image imgItem = new Image();
                        imgItem.ImageUrl = GetImageUrl(datarow["CODIGO"].ToString());

                        HtmlGenericControl HtmlSpan = new HtmlGenericControl("span");
                        HtmlSpan.InnerText = datarow["DESCRIPCION"].ToString();

                        PanelItem.Controls.Add(imgItem);
                        PanelItem.Controls.Add(HtmlSpan);
                        PanelContent.Controls.Add(PanelItem);

                        itemCount++;
                    }
                }
            }
            return(itemCount);
        }
        /// <summary>
        /// Will use insert adapter and comparer and IFilter if they are set. Observes the list for changes.
        /// </summary>
        /// <param name="items"></param>
        public void InsertSorted(System.Collections.IEnumerable items, bool trackChanges)
        {
            if (trackChanges && items is INotifyCollectionChanged)
            {
                (items as INotifyCollectionChanged).CollectionChanged += _itemsCollectionChangedHandler;
                _listsWeAreObserving.Add(items as INotifyCollectionChanged);
            }

            IEnumerator i = items.GetEnumerator();

            while (i.MoveNext())
            {
                if (i.Current is T)
                {
                    InsertSorted((T)i.Current);
                }
            }
        }
        private static Type GetItemType(System.Collections.IEnumerable list)
        {
            Type enumerableType     = list.GetType();
            Type enumerableItemType = null;

            if (IsEnumerableType(enumerableType))
            {
                enumerableItemType = GetEnumerableItemType(enumerableType);
            }
            if ((enumerableItemType == null) || (enumerableItemType == typeof(object)))
            {
                IEnumerator enumerator = list.GetEnumerator();
                if (enumerator.MoveNext() && (enumerator.Current != null))
                {
                    return(enumerator.Current.GetType());
                }
            }
            return(enumerableItemType);
        }
示例#28
0
        /// <summary>
        /// Set up a table-valued parameter to a procedure.
        /// </summary>
        /// <param name="command">The command to operate on.</param>
        /// <param name="parameter">The parameter to set up.</param>
        /// <param name="list">The list of records.</param>
        /// <param name="listType">The type of object in the list.</param>
        public override void SetupTableValuedParameter(IDbCommand command, IDataParameter parameter, System.Collections.IEnumerable list, Type listType)
        {
            if (command == null)
            {
                throw new ArgumentNullException("command");
            }
            if (list == null)
            {
                throw new ArgumentNullException("list");
            }

            // if the list is empty, then we can optimize by omitting the table
            if (command.CommandType == CommandType.StoredProcedure && !list.GetEnumerator().MoveNext())
            {
                parameter.Value = null;
                return;
            }

            // allow the provider to make sure the table parameter is set up properly
            string tableTypeName = GetTableParameterTypeName(parameter, listType);

            // see if we already have a reader for the given type and table type name
            // we can't use the schema cache because we don't have a schema yet
            var          key          = Tuple.Create <string, Type>(tableTypeName, listType);
            ObjectReader objectReader = (ObjectReader)_tvpReaders.GetOrAdd(
                key,
                k => command.Connection.ExecuteAndAutoClose(
                    _ => null,
                    (_, __) =>
            {
                using (var reader = GetTableTypeSchema(command, parameter))
                    return(ObjectReader.GetObjectReader(command, reader, listType));
            },
                    CommandBehavior.Default));

            // create the structured parameter
            parameter.Value = new ObjectListDbDataReader(objectReader, list);
        }
示例#29
0
文件: Linq.cs 项目: emadkaramad/Olive
        /// <summary>
        /// Determines whether this least contains at least the specified number of items.
        /// This can be faster than calling "x.Count() >= N" for complex iterators.
        /// </summary>
        public static bool ContainsAtLeast(this System.Collections.IEnumerable @this, int numberOfItems)
        {
            // Special case for List:
            if (@this is ICollection asList)
            {
                return(asList.Count >= numberOfItems);
            }

            var itemsCount = 0;
            var result     = itemsCount == numberOfItems;
            var enumerator = @this.GetEnumerator();

            while (enumerator.MoveNext())
            {
                itemsCount++;

                if (itemsCount >= numberOfItems)
                {
                    return(true);
                }
            }

            return(result);
        }
示例#30
0
 internal StringEnumerator(StringCollection mappings)
 {
     _temp = (IEnumerable)(mappings);
     _baseEnumerator = _temp.GetEnumerator();
 }
示例#31
0
        protected static string GetComparisonStatement(StandardProviderParameters std, esDynamicQuerySerializable query, List <esComparison> items, string prefix)
        {
            string sql   = String.Empty;
            string comma = String.Empty;

            IDynamicQuerySerializableInternal iQuery = query as IDynamicQuerySerializableInternal;

            //=======================================
            // WHERE
            //=======================================
            if (items != null)
            {
                sql += prefix;

                DbType paramType = DbType.String;

                string compareTo = String.Empty;
                foreach (esComparison comparisonItem in items)
                {
                    paramType = DbType.String;

                    esComparison.esComparisonData comparisonData = (esComparison.esComparisonData)comparisonItem;
                    esDynamicQuerySerializable    subQuery       = null;

                    bool requiresParam        = true;
                    bool needsStringParameter = false;
                    std.needsIntegerParameter = false;

                    if (comparisonData.IsParenthesis)
                    {
                        if (comparisonData.Parenthesis == esParenthesis.Open)
                        {
                            sql += "(";
                        }
                        else
                        {
                            sql += ")";
                        }

                        continue;
                    }

                    if (comparisonData.IsConjunction)
                    {
                        switch (comparisonData.Conjunction)
                        {
                        case esConjunction.And: sql += " AND "; break;

                        case esConjunction.Or: sql += " OR "; break;

                        case esConjunction.AndNot: sql += " AND NOT "; break;

                        case esConjunction.OrNot: sql += " OR NOT "; break;
                        }
                        continue;
                    }

                    Dictionary <string, SqlParameter> types = null;
                    if (comparisonData.Column.Query != null)
                    {
                        IDynamicQuerySerializableInternal iLocalQuery = comparisonData.Column.Query as IDynamicQuerySerializableInternal;
                        types = Cache.GetParameters(iLocalQuery.DataID, (esProviderSpecificMetadata)iLocalQuery.ProviderMetadata, (esColumnMetadataCollection)iLocalQuery.Columns);
                    }

                    if (comparisonData.IsLiteral)
                    {
                        if (comparisonData.Column.Name[0] == '<')
                        {
                            sql += comparisonData.Column.Name.Substring(1, comparisonData.Column.Name.Length - 2);
                        }
                        else
                        {
                            sql += comparisonData.Column.Name;
                        }
                        continue;
                    }

                    if (comparisonData.ComparisonColumn.Name == null)
                    {
                        subQuery = comparisonData.Value as esDynamicQuerySerializable;

                        if (subQuery == null)
                        {
                            if (comparisonData.Column.Name != null)
                            {
                                IDynamicQuerySerializableInternal iColQuery = comparisonData.Column.Query as IDynamicQuerySerializableInternal;
                                esColumnMetadataCollection        columns   = (esColumnMetadataCollection)iColQuery.Columns;
                                compareTo = Delimiters.Param + columns[comparisonData.Column.Name].PropertyName + (++std.pindex).ToString();
                            }
                            else
                            {
                                compareTo = Delimiters.Param + "Expr" + (++std.pindex).ToString();
                            }
                        }
                        else
                        {
                            // It's a sub query
                            compareTo     = GetSubquerySearchCondition(subQuery) + " (" + BuildQuery(std, subQuery) + ") ";
                            requiresParam = false;
                        }
                    }
                    else
                    {
                        compareTo     = GetColumnName(comparisonData.ComparisonColumn);
                        requiresParam = false;
                    }

                    switch (comparisonData.Operand)
                    {
                    case esComparisonOperand.Exists:
                        sql += " EXISTS" + compareTo;
                        break;

                    case esComparisonOperand.NotExists:
                        sql += " NOT EXISTS" + compareTo;
                        break;

                    //-----------------------------------------------------------
                    // Comparison operators, left side vs right side
                    //-----------------------------------------------------------
                    case esComparisonOperand.Equal:
                        if (comparisonData.ItemFirst)
                        {
                            sql += ApplyWhereSubOperations(std, query, comparisonData) + " = " + compareTo;
                        }
                        else
                        {
                            sql += compareTo + " = " + ApplyWhereSubOperations(std, query, comparisonData);
                        }
                        break;

                    case esComparisonOperand.NotEqual:
                        if (comparisonData.ItemFirst)
                        {
                            sql += ApplyWhereSubOperations(std, query, comparisonData) + " <> " + compareTo;
                        }
                        else
                        {
                            sql += compareTo + " <> " + ApplyWhereSubOperations(std, query, comparisonData);
                        }
                        break;

                    case esComparisonOperand.GreaterThan:
                        if (comparisonData.ItemFirst)
                        {
                            sql += ApplyWhereSubOperations(std, query, comparisonData) + " > " + compareTo;
                        }
                        else
                        {
                            sql += compareTo + " > " + ApplyWhereSubOperations(std, query, comparisonData);
                        }
                        break;

                    case esComparisonOperand.LessThan:
                        if (comparisonData.ItemFirst)
                        {
                            sql += ApplyWhereSubOperations(std, query, comparisonData) + " < " + compareTo;
                        }
                        else
                        {
                            sql += compareTo + " < " + ApplyWhereSubOperations(std, query, comparisonData);
                        }
                        break;

                    case esComparisonOperand.LessThanOrEqual:
                        if (comparisonData.ItemFirst)
                        {
                            sql += ApplyWhereSubOperations(std, query, comparisonData) + " <= " + compareTo;
                        }
                        else
                        {
                            sql += compareTo + " <= " + ApplyWhereSubOperations(std, query, comparisonData);
                        }
                        break;

                    case esComparisonOperand.GreaterThanOrEqual:
                        if (comparisonData.ItemFirst)
                        {
                            sql += ApplyWhereSubOperations(std, query, comparisonData) + " >= " + compareTo;
                        }
                        else
                        {
                            sql += compareTo + " >= " + ApplyWhereSubOperations(std, query, comparisonData);
                        }
                        break;

                    case esComparisonOperand.Like:
                        string esc = comparisonData.LikeEscape.ToString();
                        if (String.IsNullOrEmpty(esc) || esc == "\0")
                        {
                            sql += ApplyWhereSubOperations(std, query, comparisonData) + " LIKE " + compareTo;
                            needsStringParameter = true;
                        }
                        else
                        {
                            sql += ApplyWhereSubOperations(std, query, comparisonData) + " LIKE " + compareTo;
                            sql += " ESCAPE '" + esc + "'";
                            needsStringParameter = true;
                        }
                        break;

                    case esComparisonOperand.NotLike:
                        esc = comparisonData.LikeEscape.ToString();
                        if (String.IsNullOrEmpty(esc) || esc == "\0")
                        {
                            sql += ApplyWhereSubOperations(std, query, comparisonData) + " NOT LIKE " + compareTo;
                            needsStringParameter = true;
                        }
                        else
                        {
                            sql += ApplyWhereSubOperations(std, query, comparisonData) + " NOT LIKE " + compareTo;
                            sql += " ESCAPE '" + esc + "'";
                            needsStringParameter = true;
                        }
                        break;

                    case esComparisonOperand.Contains:
                        sql                 += " CONTAINS(" + GetColumnName(comparisonData.Column) + ", " + compareTo + ")";
                        paramType            = DbType.AnsiStringFixedLength;
                        needsStringParameter = true;
                        break;

                    case esComparisonOperand.IsNull:
                        sql          += ApplyWhereSubOperations(std, query, comparisonData) + " IS NULL";
                        requiresParam = false;
                        break;

                    case esComparisonOperand.IsNotNull:
                        sql          += ApplyWhereSubOperations(std, query, comparisonData) + " IS NOT NULL";
                        requiresParam = false;
                        break;

                    case esComparisonOperand.In:
                    case esComparisonOperand.NotIn:
                    {
                        if (subQuery != null)
                        {
                            // They used a subquery for In or Not
                            sql += ApplyWhereSubOperations(std, query, comparisonData);
                            sql += (comparisonData.Operand == esComparisonOperand.In) ? " IN" : " NOT IN";
                            sql += compareTo;
                        }
                        else
                        {
                            comma = String.Empty;
                            if (comparisonData.Operand == esComparisonOperand.In)
                            {
                                sql += ApplyWhereSubOperations(std, query, comparisonData) + " IN (";
                            }
                            else
                            {
                                sql += ApplyWhereSubOperations(std, query, comparisonData) + " NOT IN (";
                            }

                            foreach (object oin in comparisonData.Values)
                            {
                                string str = oin as string;
                                if (str != null)
                                {
                                    // STRING
                                    sql  += comma + Delimiters.StringOpen + str + Delimiters.StringClose;
                                    comma = ",";
                                }
                                else if (null != oin as System.Collections.IEnumerable)
                                {
                                    // LIST OR COLLECTION OF SOME SORT
                                    System.Collections.IEnumerable enumer = oin as System.Collections.IEnumerable;
                                    if (enumer != null)
                                    {
                                        System.Collections.IEnumerator iter = enumer.GetEnumerator();

                                        while (iter.MoveNext())
                                        {
                                            object o = iter.Current;

                                            string soin = o as string;

                                            if (soin != null)
                                            {
                                                sql += comma + Delimiters.StringOpen + soin + Delimiters.StringClose;
                                            }
                                            else
                                            {
                                                sql += comma + Convert.ToString(o);
                                            }

                                            comma = ",";
                                        }
                                    }
                                }
                                else
                                {
                                    // NON STRING OR LIST
                                    sql  += comma + Convert.ToString(oin);
                                    comma = ",";
                                }
                            }
                            sql          += ")";
                            requiresParam = false;
                        }
                    }
                    break;

                    case esComparisonOperand.Between:

                        SqlCommand sqlCommand = std.cmd as SqlCommand;

                        sql += ApplyWhereSubOperations(std, query, comparisonData) + " BETWEEN ";
                        sql += compareTo;
                        if (comparisonData.ComparisonColumn.Name == null)
                        {
                            sqlCommand.Parameters.AddWithValue(compareTo, comparisonData.BetweenBegin);
                        }

                        if (comparisonData.ComparisonColumn2.Name == null)
                        {
                            IDynamicQuerySerializableInternal iColQuery = comparisonData.Column.Query as IDynamicQuerySerializableInternal;
                            esColumnMetadataCollection        columns   = (esColumnMetadataCollection)iColQuery.Columns;
                            compareTo = Delimiters.Param + columns[comparisonData.Column.Name].PropertyName + (++std.pindex).ToString();

                            sql += " AND " + compareTo;
                            sqlCommand.Parameters.AddWithValue(compareTo, comparisonData.BetweenEnd);
                        }
                        else
                        {
                            sql += " AND " + Delimiters.ColumnOpen + comparisonData.ComparisonColumn2 + Delimiters.ColumnClose;
                        }

                        requiresParam = false;
                        break;
                    }

                    if (requiresParam)
                    {
                        SqlParameter p;

                        if (comparisonData.Column.Name != null)
                        {
                            p = types[comparisonData.Column.Name];

                            p = Cache.CloneParameter(p);
                            p.ParameterName = compareTo;
                            p.Value         = comparisonData.Value;

                            if (needsStringParameter)
                            {
                                p.DbType = paramType;
                            }
                            else if (std.needsIntegerParameter)
                            {
                                p.DbType = DbType.Int32;
                            }
                        }
                        else
                        {
                            p = new SqlParameter(compareTo, comparisonData.Value);
                        }

                        std.cmd.Parameters.Add(p);
                    }
                }
            }

            return(sql);
        }
示例#32
0
 internal StringEnumerator(StringCollection mappings) {
     this.temp = (IEnumerable)(mappings);
     this.baseEnumerator = temp.GetEnumerator();
 }
 /// <summary>
 ///     Enumerator constructor
 /// </summary>
 public IPluginEnumerator(PluginCollection pluMappings)
 {
     this.iEnLocal = ((System.Collections.IEnumerable)(pluMappings));
     this.iEnBase = iEnLocal.GetEnumerator();
 }