public static void CopyTo() { var blockCollection = new BlockCollection <int>(); blockCollection.Add(new Block <int>(DefaultBlockSize) { 0, 1, 2 }); blockCollection.Add(new Block <int>(DefaultBlockSize) { 3, 4, 5 }); blockCollection.Add(new Block <int>(DefaultBlockSize) { 6, 7, 8 }); //Without shift var array1 = new Block <int> [3]; blockCollection.CopyTo(array1, 0); for (int i = 0; i < blockCollection.Count; i++) { Assert.AreEqual(blockCollection[i], array1[i]); } //With shift var array2 = new Block <int> [4]; blockCollection.CopyTo(array2, 1); for (int i = 0; i < blockCollection.Count; i++) { Assert.AreEqual(blockCollection[i], array2[i + 1]); } //Exceptions Assert.IsTrue(ExceptionManager.IsThrowActionException <ArgumentNullException, Block <int>[], int> (blockCollection.CopyTo, null, 0)); Assert.IsTrue(ExceptionManager.IsThrowActionException <ArgumentOutOfRangeException, Block <int>[], int> (blockCollection.CopyTo, array1, array1.Length - blockCollection.Count + 1)); Assert.IsTrue(ExceptionManager.IsThrowActionException <ArgumentOutOfRangeException, Block <int>[], int> (blockCollection.CopyTo, array1, -1)); }
private void inputMsgBox_SelectionChanged(object sender, RoutedEventArgs e) { try { System.Windows.Controls.RichTextBox inputTextBox = this.ChatComponent.inputMsgBox; if (inputTextBox != null) { inputTextBox.SelectionChanged -= new RoutedEventHandler(this.inputMsgBox_SelectionChanged); BlockCollection bc = inputTextBox.Document.Blocks; if (bc != null && bc.Count > 0) { Block[] blocks = new Block[bc.Count]; bc.CopyTo(blocks, 0); Block[] array = blocks; for (int i = 0; i < array.Length; i++) { Paragraph paragraph = (Paragraph)array[i]; if (paragraph != null) { Inline[] inlines = new Inline[paragraph.Inlines.Count]; paragraph.Inlines.CopyTo(inlines, 0); Inline[] array2 = inlines; for (int j = 0; j < array2.Length; j++) { Inline inline = array2[j]; if (inline is InlineUIContainer) { InlineUIContainer ui = inline as InlineUIContainer; System.Windows.Controls.Image image = ui.Child as System.Windows.Controls.Image; if (image != null) { if (image.Source != null && !System.IO.File.Exists(image.Source.ToString())) { paragraph.Inlines.Remove(inline); } } } } } } } } } catch (System.InvalidCastException ex) { this.logger.Error(ex.ToString()); } }
public static void CopyTo() { var blockCollection = new BlockCollection<int>(); blockCollection.Add(new Block<int>(DefaultBlockSize) { 0, 1, 2 }); blockCollection.Add(new Block<int>(DefaultBlockSize) { 3, 4, 5 }); blockCollection.Add(new Block<int>(DefaultBlockSize) { 6, 7, 8 }); //Without shift var array1 = new Block<int>[3]; blockCollection.CopyTo(array1, 0); for (int i = 0; i < blockCollection.Count; i++) { Assert.AreEqual(blockCollection[i], array1[i]); } //With shift var array2 = new Block<int>[4]; blockCollection.CopyTo(array2, 1); for (int i = 0; i < blockCollection.Count; i++) { Assert.AreEqual(blockCollection[i], array2[i + 1]); } //Exceptions Assert.IsTrue(ExceptionManager.IsThrowActionException <ArgumentNullException, Block<int>[], int> (blockCollection.CopyTo, null, 0)); Assert.IsTrue(ExceptionManager.IsThrowActionException <ArgumentOutOfRangeException, Block<int>[], int> (blockCollection.CopyTo, array1, array1.Length - blockCollection.Count + 1)); Assert.IsTrue(ExceptionManager.IsThrowActionException <ArgumentOutOfRangeException, Block<int>[], int> (blockCollection.CopyTo, array1, -1)); }