public static void IndexOfTest() { string[] anArray = new string[] { "one", "two", "three", "four" }; ReadOnlyObservableCollection <string> readOnlyCollection = new ReadOnlyObservableCollection <string>(new ObservableCollection <string>(anArray)); for (int i = 0; i < anArray.Length; ++i) { Assert.Equal(i, readOnlyCollection.IndexOf(anArray[i])); } Assert.Equal(-1, readOnlyCollection.IndexOf("seven")); Assert.Equal(-1, readOnlyCollection.IndexOf(null)); // testing that the first occurrence is the index returned. ObservableCollection <int> intCol = new ObservableCollection <int>(); for (int i = 0; i < 4; ++i) { intCol.Add(i % 2); } ReadOnlyObservableCollection <int> intReadOnlyCol = new ReadOnlyObservableCollection <int>(intCol); Assert.Equal(0, intReadOnlyCol.IndexOf(0)); Assert.Equal(1, intReadOnlyCol.IndexOf(1)); IList colAsIList = (IList)intReadOnlyCol; var index = colAsIList.IndexOf("stringObj"); Assert.Equal(-1, index); }
internal ImageItem Image_Previous(ImageItem currentImage) { int index = ImageCollection.IndexOf(currentImage); index = --index >= 0 ? index : ImageCollection.Count - 1; return(ImageCollection[index]); }
public int IndexOf(TOut item) { return(_ReadOnlyCollection.IndexOf(item)); }
public static void SaveToXML() { IsolatedStorageFile iso = IsolatedStorageFile.GetUserStoreForApplication(); if (!iso.FileExists("save.xml")) { using (IsolatedStorageFileStream isoStream = new IsolatedStorageFileStream("save.xml", FileMode.CreateNew, iso)) { // Write to the Isolated Storage for the user. XmlWriterSettings settings = new XmlWriterSettings(); settings.Indent = true; // Create an XmlWriter. using (XmlWriter writer = XmlWriter.Create(isoStream, settings)) { writer.WriteStartElement("SaveFile"); #region Variables writer.WriteComment("Variables?"); // Write the Variable root writer.WriteStartElement("GROUP"); writer.WriteAttributeString("name", "VARIABLES"); // Write all Variables foreach (Block b in MainPage.variableList) { writer.WriteStartElement("VARIABLE"); writer.WriteStartElement("name"); writer.WriteString(b.metadataList[1]); //name of variable writer.WriteEndElement(); writer.WriteStartElement("return"); writer.WriteString(b.metadataList[0]); //return type writer.WriteEndElement(); writer.WriteEndElement(); } // Write the close tag for Variables writer.WriteEndElement(); #endregion #region Methods writer.WriteComment("Methods?"); // Write the Method root writer.WriteStartElement("GROUP"); writer.WriteAttributeString("name", "METHODS"); // Write all Methods foreach (Block b in MainPage.methodList) { writer.WriteStartElement("METHOD"); writer.WriteStartElement("name"); writer.WriteString(b.metadataList[1]); //name of method writer.WriteEndElement(); writer.WriteStartElement("return"); writer.WriteString(b.returnType); //return type writer.WriteEndElement(); writer.WriteStartElement("PARAMETERS"); TabPage methodCode = (TabPage)MainPage.tabList[MainPage.methodList.IndexOf(b)].Content; for (int i = 0; i < methodCode.parameterBox.Items.Count; i++) { writer.WriteStartElement("PARAMETER"); Block param = methodCode.getParamAtIndex(i); writer.WriteStartElement("name"); writer.WriteString(param.metadataList[1]); //name of parameter writer.WriteEndElement(); writer.WriteStartElement("return"); writer.WriteString(param.metadataList[0]); //return type writer.WriteEndElement(); writer.WriteEndElement(); } writer.WriteEndElement(); writer.WriteEndElement(); } // Write the close tag for Methods writer.WriteEndElement(); #endregion #region Editors writer.WriteComment("Editors?"); // Write the EDITOR root writer.WriteStartElement("GROUP"); writer.WriteAttributeString("name", "EDITORS"); // Write all EDDT's foreach (EditorDragDropTarget EDDT in MainPage.editorLists) { ReadOnlyObservableCollection <Block> collection = EDDT.getTreeList(); //get tree list writer.WriteStartElement("EDITOR"); writer.WriteAttributeString("name", EDDT.Name); foreach (Block b in collection) { writer.WriteStartElement("BLOCK"); writer.WriteAttributeString("type", b.Text); //type of block writer.WriteStartElement("LINE"); writer.WriteString(collection.IndexOf(b).ToString()); //line number of block writer.WriteEndElement(); if (b.Text.Equals("METHOD")) { writer.WriteStartElement("name"); writer.WriteString(b.metadataList[1]); //name of method writer.WriteEndElement(); } if (b.flag_hasSocks) //if there are sockets we need to dive in { WriteSockets(writer, b); } writer.WriteEndElement(); } writer.WriteEndElement(); } // Write the close tag for Variables writer.WriteEndElement(); #endregion writer.WriteEndElement(); // Write the XML to the file. writer.Flush(); } } } }