private static void TestICollectionInterfaceImpl(ICollection collection, bool supportsNullValues) { Assert.False(collection.IsSynchronized); Assert.IsType <object>(collection.SyncRoot); Assert.Same(collection.SyncRoot, collection.SyncRoot); if (supportsNullValues) { var copy = new object[collection.Count]; Assert.Throws <ArgumentOutOfRangeException>(() => copy.CopyTo(copy, -1)); Assert.All(copy, Assert.Null); Assert.Throws <ArgumentException>(() => copy.CopyTo(copy, 1)); Assert.All(copy, Assert.Null); collection.CopyTo(copy, 0); Assert.Equal(600, copy[0]); Assert.Equal(601, copy[1]); copy = new object[collection.Count + 2]; collection.CopyTo(copy, 1); Assert.Null(copy[0]); Assert.Equal(600, copy[1]); Assert.Equal(601, copy[2]); Assert.Null(copy[3]); // TODO: One of these applies to int?, while the other applies to object. Need to resolve. ////Assert.Throws<ArgumentException>(() => collection.CopyTo(new string[collection.Count], 0)); ////Assert.Throws<InvalidCastException>(() => collection.CopyTo(new string[collection.Count], 0)); } else { var copy = new int[collection.Count]; Assert.Throws <ArgumentOutOfRangeException>(() => copy.CopyTo(copy, -1)); Assert.All(copy, item => Assert.Equal(0, item)); Assert.Throws <ArgumentException>(() => copy.CopyTo(copy, 1)); Assert.All(copy, item => Assert.Equal(0, item)); collection.CopyTo(copy, 0); Assert.Equal(600, copy[0]); Assert.Equal(601, copy[1]); copy = new int[collection.Count + 2]; collection.CopyTo(copy, 1); Assert.Equal(0, copy[0]); Assert.Equal(600, copy[1]); Assert.Equal(601, copy[2]); Assert.Equal(0, copy[3]); Assert.Throws <ArgumentException>(() => collection.CopyTo(new string[collection.Count], 0)); } }
private static void TestICollectionInterfaceImpl(ICollection collection, bool supportsNullValues) { Assert.False(collection.IsSynchronized); Assert.Same(collection, collection.SyncRoot); if (supportsNullValues) { var copy = new object[collection.Count]; Assert.Throws <ArgumentOutOfRangeException>(() => collection.CopyTo(copy, -1)); Assert.All(copy, Assert.Null); Assert.Throws <ArgumentOutOfRangeException>(() => collection.CopyTo(copy, 1)); Assert.All(copy, Assert.Null); collection.CopyTo(copy, 0); Assert.Equal(600, copy[0]); Assert.Equal(601, copy[1]); copy = new object[collection.Count + 2]; collection.CopyTo(copy, 1); Assert.Null(copy[0]); Assert.Equal(600, copy[1]); Assert.Equal(601, copy[2]); Assert.Null(copy[3]); Assert.Throws <InvalidCastException>(() => collection.CopyTo(new string[collection.Count], 0)); } else { var copy = new int[collection.Count]; Assert.Throws <ArgumentOutOfRangeException>(() => collection.CopyTo(copy, -1)); Assert.All(copy, item => Assert.Equal(0, item)); Assert.Throws <ArgumentOutOfRangeException>(() => collection.CopyTo(copy, 1)); Assert.All(copy, item => Assert.Equal(0, item)); collection.CopyTo(copy, 0); Assert.Equal(600, copy[0]); Assert.Equal(601, copy[1]); copy = new int[collection.Count + 2]; collection.CopyTo(copy, 1); Assert.Equal(0, copy[0]); Assert.Equal(600, copy[1]); Assert.Equal(601, copy[2]); Assert.Equal(0, copy[3]); Assert.Throws <InvalidCastException>(() => collection.CopyTo(new string[collection.Count], 0)); } }
void ClearAllListeners_inLock(out CommonRfcommStream[] all) { System.Collections.ICollection all0 = m_listening.Values; all = new CommonRfcommStream[all0.Count]; all0.CopyTo(all, 0); m_listening.Clear(); }
public void TestCopyToValidation() { TreeStack <int> stack = CreateTreeStack(Enumerable.Range(0, 10)); Assert.Throws <ArgumentNullException>("dest", () => stack.CopyTo(null !, 0)); Assert.Throws <ArgumentOutOfRangeException>("dstIndex", () => stack.CopyTo(new int[stack.Count], -1)); Assert.Throws <ArgumentException>(string.Empty, () => stack.CopyTo(new int[stack.Count], 1)); ICollection collection = stack; Assert.Throws <ArgumentNullException>("dest", () => collection.CopyTo(null !, 0)); Assert.Throws <ArgumentOutOfRangeException>("dstIndex", () => collection.CopyTo(new int[collection.Count], -1)); Assert.Throws <ArgumentOutOfRangeException>("dstIndex", () => collection.CopyTo(Array.CreateInstance(typeof(int), new[] { stack.Count }, new[] { 1 }), 0)); Assert.Throws <ArgumentException>(string.Empty, () => collection.CopyTo(new int[collection.Count], collection.Count + 1)); Assert.Throws <ArgumentException>(null, () => collection.CopyTo(new int[stack.Count, 1], 0)); collection.CopyTo(Array.CreateInstance(typeof(int), new[] { stack.Count }, new[] { 1 }), 1); }
public Queue(System.Collections.ICollection col) { capacity = col.Count; first = capacity == 0?-1:0; last = capacity - 1; queue_array = new object[capacity]; col.CopyTo(queue_array, 0); }
public static T[] GetArrayFromCollection <T>(System.Collections.ICollection list) { if (list == null) { return(null); } T[] arr = new T[list.Count]; list.CopyTo(arr, 0); return(arr); }
static public IPersistentVector create(System.Collections.ICollection coll) { if (!(coll is ISeq) && coll.Count <= 32) { object[] array = new object[coll.Count]; coll.CopyTo(array, 0); return(createOwning(array)); } return(PersistentVector.create(RT.seq(coll))); }
private static void TestICollectionTInterfaceImpl <T>(ICollection <T> collection, bool supportsNullValues) { Assert.True(collection.IsReadOnly); Assert.Equal(2, collection.Count); if (supportsNullValues) { var copy = new T[collection.Count]; Assert.Throws <ArgumentOutOfRangeException>(() => collection.CopyTo(copy, -1)); Assert.All(copy, item => Assert.Equal(default !, item));
private ToolStripMenuItem[] GetSelectionMenuItems() { List <ToolStripMenuItem> menuItems = new List <ToolStripMenuItem>(); ISelectionService selectionService = GetService(typeof(ISelectionService)) as ISelectionService; if (selectionService != null) { ICollection selectedComps = selectionService.GetSelectedComponents(); Dictionary <CommandID, string> selectionCommands = new Dictionary <CommandID, string>(); selectionCommands.Add(StandardCommands.Cut, "Cut"); selectionCommands.Add(StandardCommands.Copy, "Copy"); selectionCommands.Add(StandardCommands.Paste, "Paste"); selectionCommands.Add(StandardCommands.Delete, "Delete"); selectionCommands.Add(StandardCommands.Undo, "Undo"); selectionCommands.Add(StandardCommands.Redo, "Redo"); foreach (CommandID id in selectionCommands.Keys) { MenuCommand command = FindCommand(id); if (command != null) { ToolStripMenuItem menuItem = new ToolStripMenuItem(selectionCommands[id], null, new EventHandler(OnMenuClicked)); menuItem.Tag = command; menuItems.Add(menuItem); } } if (selectedComps != null && selectedComps.Count == 1) { object[] comps = new object[selectedComps.Count]; selectedComps.CopyTo(comps, 0); if (comps[0].GetType() == typeof(TabControl)) { foreach (DesignerVerb verb in Verbs) { if (verb != null) { ToolStripMenuItem menuItem = new ToolStripMenuItem(verb.Text, null, new EventHandler(OnMenuClicked)); menuItem.Tag = verb; menuItems.Add(menuItem); } } } } } return(menuItems.ToArray()); }
public void TestICollectionInterface() { TestICollectionInterfaceImpl(ImmutableTreeSet.Create(600, 601), supportsNullValues: false); TestICollectionInterfaceImpl(ImmutableTreeSet.Create <int?>(600, 601), supportsNullValues: true); TestICollectionInterfaceImpl(ImmutableTreeSet.Create <object>(600, 601), supportsNullValues: true); ICollection collection = ImmutableTreeSet <int> .Empty; collection.CopyTo(new int[0], 0); // Type checks are only performed if the collection has items collection.CopyTo(new string[0], 0); collection = ImmutableTreeSet.CreateRange(Enumerable.Range(0, 100)); var array = new int[collection.Count]; collection.CopyTo(array, 0); Assert.Equal(array, collection); // Run the same set of tests on ImmutableList<T> to ensure consistent behavior TestICollectionInterfaceImpl(ImmutableList.Create(600, 601), supportsNullValues: false); TestICollectionInterfaceImpl(ImmutableList.Create <int?>(600, 601), supportsNullValues: true); TestICollectionInterfaceImpl(ImmutableList.Create <object>(600, 601), supportsNullValues: true); }
public void TestReadOnlyCollectionBuilder() { int cnt = 0; // Empty ReadOnlyCollectionBuilder <int> a = new ReadOnlyCollectionBuilder <int>(); AreEqual(0, a.Count); AreEqual(0, a.Capacity); AreEqual(a.ToReadOnlyCollection().Count, 0); AreEqual(a.ToReadOnlyCollection().Count, 0); // Simple case a.Add(5); AreEqual(1, a.Count); AreEqual(4, a.Capacity); AreEqual(a.ToReadOnlyCollection()[0], 5); AreEqual(a.ToReadOnlyCollection().Count, 0); // Will reset a = new ReadOnlyCollectionBuilder <int>(0); AreEqual(0, a.Count); AssertError <ArgumentException>(() => a = new ReadOnlyCollectionBuilder <int>(-1)); a = new ReadOnlyCollectionBuilder <int>(5); for (int i = 1; i <= 10; i++) { a.Add(i); } AreEqual(10, a.Capacity); System.Collections.ObjectModel.ReadOnlyCollection <int> readonlyCollection = a.ToReadOnlyCollection(); AreEqual(0, a.Capacity); AreEqual(readonlyCollection.Count, 10); ReadOnlyCollectionBuilder <int> b = new ReadOnlyCollectionBuilder <int>(readonlyCollection); b.Add(11); AreEqual(b.Count, 11); AssertError <ArgumentException>(() => a = new ReadOnlyCollectionBuilder <int>(null)); // Capacity tests b.Capacity = 11; AssertError <ArgumentException>(() => b.Capacity = 10); b.Capacity = 50; AreEqual(b.Count, 11); AreEqual(b.Capacity, 50); // IndexOf cases AreEqual(b.IndexOf(5), 4); AreEqual(b[4], 5); a = new ReadOnlyCollectionBuilder <int>(); AreEqual(a.IndexOf(5), -1); // Insert cases b = new ReadOnlyCollectionBuilder <int>(readonlyCollection); AssertError <ArgumentException>(() => b.Insert(11, 11)); b.Insert(2, 24); AreEqual(b.Count, 11); AreEqual(b[1], 2); AreEqual(b[2], 24); AreEqual(b[3], 3); b.Insert(11, 1234); AssertError <ArgumentException>(() => b.Insert(-1, 55)); AreEqual(b[11], 1234); AreEqual(b.ToReadOnlyCollection().Count, 12); // Remove b = new ReadOnlyCollectionBuilder <int>(readonlyCollection); AreEqual(b.Remove(2), true); AreEqual(b[0], 1); AreEqual(b[1], 3); AreEqual(b[2], 4); AreEqual(b.Remove(2), false); // RemoveAt b = new ReadOnlyCollectionBuilder <int>(readonlyCollection); b.RemoveAt(2); AreEqual(b[1], 2); AreEqual(b[2], 4); AreEqual(b[3], 5); AssertError <ArgumentException>(() => b.RemoveAt(-5)); AssertError <ArgumentException>(() => b.RemoveAt(9)); // Clear b.Clear(); AreEqual(b.Count, 0); AreEqual(b.ToReadOnlyCollection().Count, 0); b = new ReadOnlyCollectionBuilder <int>(); b.Clear(); AreEqual(b.Count, 0); // Contains b = new ReadOnlyCollectionBuilder <int>(readonlyCollection); AreEqual(b.Contains(5), true); AreEqual(b.Contains(-3), false); ReadOnlyCollectionBuilder <object> c = new ReadOnlyCollectionBuilder <object>(); c.Add("HI"); AreEqual(c.Contains("HI"), true); AreEqual(c.Contains(null), false); c.Add(null); AreEqual(c.Contains(null), true); // CopyTo b = new ReadOnlyCollectionBuilder <int>(readonlyCollection); int[] ary = new int[10]; b.CopyTo(ary, 0); AreEqual(ary[0], 1); AreEqual(ary[9], 10); // Reverse b = new ReadOnlyCollectionBuilder <int>(readonlyCollection); b.Reverse(); // 1..10 cnt = 10; for (int i = 0; i < 10; i++) { AreEqual(b[i], cnt--); } b = new ReadOnlyCollectionBuilder <int>(readonlyCollection); AssertError <ArgumentException>(() => b.Reverse(-1, 5)); AssertError <ArgumentException>(() => b.Reverse(5, -1)); b.Reverse(3, 3); // 1,2,3,4,5,6,7,8,9.10 // 1,2,3,6,5,4,7,8,9,10 AreEqual(b[1], 2); AreEqual(b[2], 3); AreEqual(b[3], 6); AreEqual(b[4], 5); AreEqual(b[5], 4); AreEqual(b[6], 7); // ToArray b = new ReadOnlyCollectionBuilder <int>(readonlyCollection); int[] intAry = b.ToArray(); AreEqual(intAry[0], 1); AreEqual(intAry[9], 10); b = new ReadOnlyCollectionBuilder <int>(); intAry = b.ToArray(); AreEqual(intAry.Length, 0); // IEnumerable cases b = new ReadOnlyCollectionBuilder <int>(readonlyCollection); cnt = 0; foreach (int i in b) { cnt++; } AreEqual(cnt, 10); b = new ReadOnlyCollectionBuilder <int>(); cnt = 0; foreach (int i in b) { cnt++; } AreEqual(cnt, 0); // Error case AssertError <InvalidOperationException>(() => ChangeWhileEnumeratingAdd()); AssertError <InvalidOperationException>(() => ChangeWhileEnumeratingRemove()); // IList members b = new ReadOnlyCollectionBuilder <int>(readonlyCollection); System.Collections.IList lst = b; // IsReadOnly AreEqual(lst.IsReadOnly, false); // Add AreEqual(lst.Add(11), 10); AreEqual(lst.Count, 11); AssertError <ArgumentException>(() => lst.Add("MOM")); AssertError <ArgumentException>(() => lst.Add(null)); c = new ReadOnlyCollectionBuilder <object>(); c.Add("HI"); c.Add(null); lst = c; lst.Add(null); AreEqual(lst.Count, 3); // Contains lst = b; AreEqual(lst.Contains(5), true); AreEqual(lst.Contains(null), false); lst = c; AreEqual(lst.Contains("HI"), true); AreEqual(lst.Contains("hi"), false); AreEqual(lst.Contains(null), true); // IndexOf lst = b; AreEqual(lst.IndexOf(null), -1); AreEqual(lst.IndexOf(1234), -1); AreEqual(lst.IndexOf(5), 4); // Insert b = new ReadOnlyCollectionBuilder <int>(readonlyCollection); lst = b; AssertError <ArgumentException>(() => lst.Insert(11, 11)); lst.Insert(2, 24); AreEqual(lst.Count, 11); AreEqual(lst[1], 2); AreEqual(lst[2], 24); AreEqual(lst[3], 3); lst.Insert(11, 1234); AssertError <ArgumentException>(() => lst.Insert(-1, 55)); AreEqual(lst[11], 1234); AssertError <ArgumentException>(() => lst.Insert(3, "MOM")); // IsFixedSize AreEqual(lst.IsFixedSize, false); // Remove b = new ReadOnlyCollectionBuilder <int>(readonlyCollection); lst = b; lst.Remove(2); AreEqual(lst[0], 1); AreEqual(lst[1], 3); AreEqual(lst[2], 4); lst.Remove(2); // Indexing lst[3] = 234; AreEqual(lst[3], 234); AssertError <ArgumentException>(() => lst[3] = null); AssertError <ArgumentException>(() => lst[3] = "HI"); // ICollection<T> // IsReadOnly System.Collections.Generic.ICollection <int> col = b; AreEqual(col.IsReadOnly, false); // ICollection b = new ReadOnlyCollectionBuilder <int>(readonlyCollection); System.Collections.ICollection col2 = b; AreEqual(col2.IsSynchronized, false); Assert(col2.SyncRoot != null); intAry = new int[10]; col2.CopyTo(intAry, 0); AreEqual(intAry[0], 1); AreEqual(intAry[9], 10); string[] str = new string[50]; AssertError <ArrayTypeMismatchException>(() => col2.CopyTo(str, 0)); }
protected override int CreateChildControls(System.Collections.IEnumerable dataSource, bool dataBinding) { int rows = base.CreateChildControls(dataSource, dataBinding); // no data rows created, create empty table if enabled if (rows == 0 && (this.ShowFooterWhenEmpty)) { // create the table Table table = this.CreateChildTable(); DataControlField[] fields; if (this.AutoGenerateColumns) { PagedDataSource source = new PagedDataSource(); source.DataSource = dataSource; System.Collections.ICollection autoGeneratedColumns = this.CreateColumns(source, true); fields = new DataControlField[autoGeneratedColumns.Count]; autoGeneratedColumns.CopyTo(fields, 0); } else { fields = new DataControlField[this.Columns.Count]; this.Columns.CopyTo(fields, 0); } if (this.ShowHeaderWhenEmpty) { // create a new header row GridViewRow headerRow = base.CreateRow(-1, -1, DataControlRowType.Header, DataControlRowState.Normal); this.InitializeRow(headerRow, fields); // add the header row to the table table.Rows.Add(headerRow); } // create the empty row GridViewRow emptyRow = new GridViewRow(-1, -1, DataControlRowType.EmptyDataRow, DataControlRowState.Normal); TableCell cell = new TableCell(); cell.ColumnSpan = fields.Length; cell.Width = Unit.Percentage(100); // respect the precedence order if both EmptyDataTemplate // and EmptyDataText are both supplied ... if (this.EmptyDataTemplate != null) { this.EmptyDataTemplate.InstantiateIn(cell); } else if (!string.IsNullOrEmpty(this.EmptyDataText)) { cell.Controls.Add(new LiteralControl(EmptyDataText)); } emptyRow.Cells.Add(cell); table.Rows.Add(emptyRow); if (this.ShowFooterWhenEmpty) { // create footer row _footerRow2 = base.CreateRow(-1, -1, DataControlRowType.Footer, DataControlRowState.Normal); this.InitializeRow(_footerRow2, fields); // add the footer to the table table.Rows.Add(_footerRow2); } this.Controls.Clear(); this.Controls.Add(table); } return(rows); }
private void saveButton_Click(object sender, EventArgs e)//save file when save button is clicked { List <string> itemsRewarded = new List <string>(); //quest.saveQuest(); quest.questNumber += 1; string fileName = "QU_" + quest.questNumber + "data" + ".txt"; //get quest id for (int i = 1; i <= quest._numItemsRewarded; i++) //add items to item list { itemsRewarded.Add("IT_" + i); } //put data in file System.IO.TextWriter tw = new System.IO.StreamWriter(fileName); tw.WriteLine("Quest ID : QU_" + quest.questNumber); tw.WriteLine("Quest Name : " + quest._questName); tw.WriteLine("Quest Level : " + quest._questLevel); tw.WriteLine("Experience Reward : " + quest._experienceReward); tw.WriteLine("Cash Reward : " + quest._cashReward); tw.WriteLine("Quest Difficulty : " + quest.questDifficulty); tw.WriteLine("Is Quest Timed : " + quest._isThisQuestTimed); if (quest._isThisQuestTimed == true) { tw.WriteLine("Timer : " + quest.questTimer); } string itemData = ""; for (int i = 0; i < itemsRewarded.Count; i++)//add items to data string { if (i == itemsRewarded.Count - 1) { itemData = itemData + itemsRewarded[i]; tw.WriteLine(itemData); } else if (i == 0) { itemData = "Items Rewarded : " + itemsRewarded[i] + " , "; } else { itemData = itemData + itemsRewarded[i] + " , "; } } tw.WriteLine("Quest Description : " + quest.questDescription); tw.WriteLine("Steps: "); int[] stepGoalIndex = new int[quest._stepsGoal.Count]; string[] stepGoalValue = new string[quest._stepsGoal.Count]; System.Collections.ICollection keyCollection = quest._stepsGoal.Keys; keyCollection.CopyTo(stepGoalIndex, 0); System.Collections.ICollection valueCollection = quest._stepsGoal.Values; valueCollection.CopyTo(stepGoalValue, 0); string stepNum = ""; int stepIndex = 0; for (int j = 0; j < quest.questSteps.Count; j++) { tw.WriteLine("Step ID : " + quest.questSteps[j]); //get index that this step id corresponds to in the step data lists stepNum = quest.questSteps[j].Substring(quest.questSteps[j].IndexOf("_") + 1); stepIndex = int.Parse(stepNum); stepIndex -= 1; tw.WriteLine("Step Description : " + quest._stepsDescription[stepIndex]); tw.WriteLine("Does step complete quest : " + quest._isCompletionStep[stepIndex]); tw.WriteLine("Step Type : " + quest._stepsType[stepIndex]); string stepGoalIndexValue = stepGoalValue[stepIndex]; if (quest._stepsType[stepIndex] == "Kill") { tw.WriteLine("Kill Number : " + stepGoalIndexValue); } else if (quest._stepsType[stepIndex] == "Explore") { tw.WriteLine("Location ID : " + stepGoalIndexValue); } else { tw.WriteLine("Conversation ID : " + stepGoalIndexValue); } } itemsRewarded.Clear(); tw.Close(); }
// Implement the ICollection<T> interface. public void CopyTo(T[] array, int index) { coll.CopyTo(array, index); }
/// <summary> /// Fill Table According to data /// <note type="note"> /// The table should has one template row with cells and controls already. /// And the template row will be removed automatically. /// The data should in the order of the table column. /// </note> /// </summary> /// <param name="t">Table</param> /// <param name="dt">DataBase</param> /// <param name="templateRowIndex">templateRowIndex, default is 1</param> /// <example> /// <code> /// <asp:Table ID="TableScoreExchangeInfo" runat="server" CssClass="table borderTopCorner borderAround" CellPadding="0" CellSpacing="0" ForeColor="Black" BorderStyle="None" /// BorderColor="White" BackColor="White" style="text-overflow:ellipsis;overflow:auto;" OnPreRender="TableScoreExchangeInfo_OnPreRender"> /// <asp:TableRow ID="TableRow32" runat="server" CssClass="tableOddRow" Height="27px"> /// <asp:TableCell ID="TableCell100" runat="server" ColumnSpan="1" HorizontalAlign="Center" CssClass="tableHeaderRow borderAround" BackColor="White"> /// <asp:Label ID="Label63" runat="server" Text="积分卡" CssClass="padding0px2px0px2px"></asp:Label> /// </asp:TableCell> /// <asp:TableCell ID="TableCell101" runat="server" ColumnSpan="1" HorizontalAlign="Center" CssClass="tableHeaderRow borderAround" BackColor="White"> /// <asp:Label ID="Label64" runat="server" Text="兑换类型" CssClass="padding0px2px0px2px"></asp:Label> /// </asp:TableCell> /// <asp:TableCell ID="TableCell102" runat="server" ColumnSpan="1" HorizontalAlign="Center" CssClass="tableHeaderRow borderAround" BackColor="White"> /// <asp:Label ID="Label65" runat="server" Text="兑换积分" CssClass="padding0px2px0px2px"></asp:Label> /// </asp:TableCell> /// <asp:TableCell ID="TableCell103" runat="server" ColumnSpan="1" HorizontalAlign="Center" CssClass="tableHeaderRow borderAround" BackColor="White"> /// <asp:Label ID="Label66" runat="server" Text="兑换礼品" CssClass="padding0px2px0px2px"></asp:Label> /// </asp:TableCell> /// <asp:TableCell ID="TableCell104" runat="server" ColumnSpan="1" HorizontalAlign="Center" CssClass="tableHeaderRow borderAround" BackColor="White"> /// <asp:Label ID="Label67" runat="server" Text="重打印兑换单" CssClass="padding0px2px0px2px"></asp:Label> /// </asp:TableCell> /// </asp:TableRow> /// <asp:TableRow ID="TableRow31" runat="server" CssClass="tableOddRow" Height="27px"> /// <asp:TableCell ID="TableCell69" runat="server" ColumnSpan="1" HorizontalAlign="Center" CssClass="borderAround" BackColor="White"> /// <asp:Label ID="Label34" runat="server" Text="" CssClass="padding0px2px0px2px"></asp:Label> /// </asp:TableCell> /// <asp:TableCell ID="TableCell73" runat="server" ColumnSpan="1" HorizontalAlign="Center" CssClass="borderAround" BackColor="White"> /// <asp:Label ID="Label38" runat="server" Text="" CssClass="padding0px2px0px2px"></asp:Label> /// </asp:TableCell> /// <asp:TableCell ID="TableCell74" runat="server" ColumnSpan="1" HorizontalAlign="Center" CssClass="borderAround" BackColor="White"> /// <asp:Label ID="Label39" runat="server" Text="" CssClass="padding0px2px0px2px"></asp:Label> /// </asp:TableCell> /// <asp:TableCell ID="TableCell79" runat="server" ColumnSpan="1" HorizontalAlign="Center" CssClass="borderAround" BackColor="White"> /// <asp:Label ID="Label44" runat="server" Text="" CssClass="padding0px2px0px2px"></asp:Label> /// </asp:TableCell> /// <asp:TableCell ID="TableCell95" runat="server" ColumnSpan="1" HorizontalAlign="Center" CssClass="borderAround" BackColor="White"> /// <asp:Label ID="Label62" runat="server" Text="" CssClass="padding0px2px0px2px"></asp:Label> /// </asp:TableCell> /// </asp:TableRow> /// </asp:Table> /// </code> /// <code> /// RF.GlobalClass.WebForm.fillTableAccordingToData(TableScoreExchangeInfo, dataSet.Tables["ScoreData", "ScoreDetails"]); /// </code> /// </example> public static void fillTableAccordingToData(Table t, DataTable dt, DataTable dtInfo = null, int templateRowIndex = 1, int templateFooterRowIndex = -1, String ellipsisTitle = "{ellipsis}", String ellipsisCls = "Ellipsis") { if (null == t || null == dt) { return; } else { } try { TableRow[] trs = new TableRow[] { }; List <TableRow> ltr = new List <TableRow>(); TableRow tr; TableCell tc; #region draw table DataRow dr; int dtRowsCount = dt.Rows.Count; int drItemArrayLength; TableRow tempTableRow = t.Rows[templateRowIndex]; int cellsCount = tempTableRow.Cells.Count; TableCell tempTableCell; AttributeCollection act = tempTableRow.Attributes; for (int dti = 0; dti < dtRowsCount; dti++) { dr = dt.Rows[dti]; tr = new System.Web.UI.WebControls.TableRow(); drItemArrayLength = dr.ItemArray.Length; #region copy style System.Collections.ICollection attrKeys = act.Keys; string[] keys = new string[] { }; attrKeys.CopyTo(keys, 0); int keysLength = keys.Length; string keyName = String.Empty; for (int ki = 0; ki < keysLength; ki++) { keyName = keys[ki]; tr.Attributes.Add(keyName, act[keyName]); } tr.CssClass = tempTableRow.CssClass; tr.Height = tempTableRow.Height; tr.Width = tempTableRow.Width; tr.Style.Value = tempTableRow.Style.Value; keys = new string[] { }; tempTableRow.Style.Keys.CopyTo(keys, 0); keysLength = keys.Length; for (int ki = 0; ki < keysLength; ki++) { keyName = keys[ki]; tr.Style.Add(keyName, tempTableRow.Style[keyName]); } tr.ToolTip = tempTableRow.ToolTip; #endregion for (int dri = 0; dri < cellsCount; dri++) { tempTableCell = tempTableRow.Cells[dri]; tc = new System.Web.UI.WebControls.TableCell(); #region copy cell controls System.Web.UI.ControlCollection tempTableCellControls = tempTableCell.Controls; foreach (Control control in tempTableCellControls) { Control _c = RF.GlobalClass.WebForm.ControlCollection.CloneControl(control); if (null != _c) { tc.Controls.Add(_c); } else { } } #endregion #region bind data if (dri < drItemArrayLength && tc.Controls.Count > 0) { try { (tc.Controls[0] as ITextControl).Text = dr.ItemArray.GetValue(dri) as String; if ((tc.Controls[0] as WebControl).CssClass.Split(' ').Contains <string>(ellipsisCls)) { if ((tc.Controls[0] as WebControl).ToolTip.Contains(ellipsisTitle)) { (tc.Controls[0] as WebControl).ToolTip = (tc.Controls[0] as WebControl).ToolTip.Replace(ellipsisTitle, (tc.Controls[0] as ITextControl).Text); } else if ((tc.Controls[0] as WebControl).ToolTip == String.Empty) { (tc.Controls[0] as WebControl).ToolTip = (tc.Controls[0] as ITextControl).Text; } else { } } else { } } catch (Exception ex) { } } else { } #endregion #region customized attributes keys = new string[] { }; tempTableCell.Attributes.Keys.CopyTo(keys, 0); keysLength = keys.Length; for (int ki = 0; ki < keysLength; ki++) { keyName = keys[ki]; tc.Attributes.Add(keyName, tempTableCell.Attributes[keyName]); } #endregion #region copy cell style tc.CssClass = tempTableCell.CssClass; tc.Height = tempTableCell.Height; tc.Width = tempTableCell.Width; keys = new string[] { }; tempTableCell.Style.Keys.CopyTo(keys, 0); keysLength = keys.Length; for (int ki = 0; ki < keysLength; ki++) { keyName = keys[ki]; tc.Style.Add(keyName, tempTableCell.Style[keyName]); } tc.ColumnSpan = tempTableCell.ColumnSpan; tc.RowSpan = tempTableCell.RowSpan; tc.BackColor = tempTableCell.BackColor; tc.ToolTip = tempTableCell.ToolTip; #endregion tr.Cells.Add(tc); } t.Rows.AddAt(templateRowIndex, tr); ltr.Add(tr); } /* * trs = ltr.ToArray(); * if (t.Rows.Count > 2) * { * TableRow[] ltra = new TableRow[(t.Rows.Count - 2)]; * t.Rows.CopyTo(ltra, 0); * trs = trs.Concat<TableRow>(ltra).ToArray(); * } * else { } * t.Rows.AddRange(trs); */ t.Rows.Remove(tempTableRow); #endregion #region draw table info if (t.Rows.Count >= dtRowsCount + 2) { if (templateFooterRowIndex > 0 && t.Rows.Count > templateFooterRowIndex) { // dtRowsCount + 1 : consider there is a header. TableRow tempTableFooterRow = t.Rows[dtRowsCount + 1]; dtInfo = dtInfo ?? new DataTable(); Boolean tmpBool = true; dtInfo.Rows[0].ItemArray.Select(delegate(object obj, int idx) { foreach (Control c in tempTableFooterRow.Controls) { switch (idx) { case 0: if (true == (c as WebControl).CssClass.Contains("RowTotalCount")) { (c as ITextControl).Text = obj + ""; } else { } break; case 1: if (true == (c as WebControl).CssClass.Contains("PerPageRowCount")) { (c as ITextControl).Text = obj + ""; } else { } break; case 2: if (true == (c as WebControl).CssClass.Contains("PageTotalCount")) { (c as ITextControl).Text = obj + ""; } else { } break; case 3: if (true == (c as WebControl).CssClass.Contains("pageFirst")) { tmpBool = (c as WebControl).Enabled = Boolean.TryParse(obj.ToString(), out tmpBool) ? tmpBool : tmpBool; } else { } break; case 4: if (true == (c as WebControl).CssClass.Contains("pagePrev")) { tmpBool = (c as WebControl).Enabled = Boolean.TryParse(obj.ToString(), out tmpBool) ? tmpBool : tmpBool; } else { } break; case 5: if (true == (c as WebControl).CssClass.Contains("pageNext")) { tmpBool = (c as WebControl).Enabled = Boolean.TryParse(obj.ToString(), out tmpBool) ? tmpBool : tmpBool; } else { } break; case 6: if (true == (c as WebControl).CssClass.Contains("pageLast")) { tmpBool = (c as WebControl).Enabled = Boolean.TryParse(obj.ToString(), out tmpBool) ? tmpBool : tmpBool; } else { } break; case 7: if (true == (c as WebControl).CssClass.Contains("CurrPageNum")) { (c as ITextControl).Text = obj + ""; } else { } break; default: break; } } return(obj); }); } else { } } else { } #endregion } catch (Exception ex) { } }
public override IList <IReportParameterValue> GetReportParameterValues(ResolveParameterValue resolver) { List <Type> argumentTypes = new List <Type>(); List <object> arguments = new List <object>(); foreach (MethodArgumentEntry argument in _methodArguments) { // also gets moved into get Type targetType = argument.type; object value = null; argumentTypes.Add(targetType); switch (argument.source) { case MethodArgumentSource.Callback: value = resolver(argument.name); break; case MethodArgumentSource.Constant: value = argument.value; break; } arguments.Add(ConversionHelper.Convert(value, targetType)); } object classInstance = _type.GetConstructor(Type.EmptyTypes).Invoke(new object[0]); MethodInfo methodInfo = _type.GetMethod( _methodName, BindingFlags.Public | BindingFlags.FlattenHierarchy | BindingFlags.Instance, null, argumentTypes.ToArray(), new ParameterModifier[0]); object result = methodInfo.Invoke(classInstance, arguments.ToArray()); object[] items = null; if (result.GetType().IsArray) { items = (object[])result; } else { foreach (Type t in result.GetType().GetInterfaces()) { if (t.Equals(typeof(System.Collections.ICollection))) { System.Collections.ICollection c = (System.Collections.ICollection)result; items = new object[c.Count]; c.CopyTo(items, 0); } if (t.Equals(typeof(ICollection <object>))) { ICollection <object> c = (ICollection <object>)result; items = new object[c.Count]; c.CopyTo(items, 0); } } if (items == null) { items = new object[] { result }; } } foreach (object item in items) { ReportParameterValue reportParameterValue = new ReportParameterValue(); reportParameterValue.Label = GetPropertyValue(item, _parameterLabelValuePair["Label"]).ToString(); reportParameterValue.Value = GetPropertyValue(item, _parameterLabelValuePair["Value"]).ToString(); reportParameterValues.Add(reportParameterValue); } return(reportParameterValues); }
/// <summary> /// Copies the elements of the collection to an array, starting at a specific array index. /// </summary> /// <param name="array">The one-dimensional array that is the destination of the elements copied from the collection. The array must have zero-based indexing.</param> /// <param name="arrayIndex">The zero-based index in <paramref name="array"/> at which copying begins.</param> /// <exception cref="ArgumentNullException">If <paramref name="array"/> is <see langword="null"/>.</exception> /// <exception cref="ArgumentOutOfRangeException">If <paramref name="arrayIndex"/> is less than 0.</exception> /// <exception cref="ArgumentException"> /// If <paramref name="array"/> is multidimensional. /// <para>-or-</para> /// <para>If the number of elements in the source collection is greater than the available space from <paramref name="arrayIndex"/> to the end of the destination <paramref name="array"/>.</para> /// <para>-or-</para> /// <para>If the type <typeparamref name="TValue"/> cannot be cast automatically to the type of the destination <paramref name="array"/>.</para> /// </exception> public void CopyTo(TValue[] array, int arrayIndex) { _values.CopyTo(array, arrayIndex); }
/// <summary> /// Copies the elements of the collection to an array, starting at a specific array index. /// </summary> /// <param name="array">The one-dimensional array that is the destination of the elements copied from the collection. The array must have zero-based indexing.</param> /// <param name="arrayIndex">The zero-based index in <paramref name="array"/> at which copying begins.</param> /// <exception cref="ArgumentNullException">If <paramref name="array"/> is <see langword="null"/>.</exception> /// <exception cref="ArgumentOutOfRangeException">If <paramref name="arrayIndex"/> is less than 0.</exception> /// <exception cref="ArgumentException"> /// If <paramref name="array"/> is multidimensional. /// <para>-or-</para> /// <para>If the number of elements in the source collection is greater than the available space from <paramref name="arrayIndex"/> to the end of the destination <paramref name="array"/>.</para> /// <para>-or-</para> /// <para>If the type <typeparamref name="TKey"/> cannot be cast automatically to the type of the destination <paramref name="array"/>.</para> /// </exception> public void CopyTo(TKey[] array, int arrayIndex) { _keys.CopyTo(array, arrayIndex); }
/// <summary> /// Create a <see cref="LazilyPersistentVector">LazilyPersistentVector</see> from an ICollection of items. /// </summary> /// <param name="coll">The collection of items.</param> /// <returns>A <see cref="LazilyPersistentVector">LazilyPersistentVector</see>.</returns> static public IPersistentVector create(System.Collections.ICollection coll) { object[] array = new object[coll.Count]; coll.CopyTo(array, 0); return(createOwning(array)); }