using System; using System.Collections; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Linq; using System.Text; using System.Xml; using System.Windows.Forms; using System.Reflection; using System.Drawing; using TradeIdeas; namespace TradeIdeas.TIProGUI { public static class ExtensionMethods { //apparently .Clear() doesn't dispose of the object. Usually is taken care by //garbage collector. However, due to the large number of controls within some of windows // of this application..we don't want to wait for GC. We want them disposed right away //after clearing. We're trying to avoid the "error creating window handle" exception" //source: http://stackoverflow.com/questions/1969705/clear-controls-does-not-dispose-them-what-is-the-risk public static void Clear(this Control.ControlCollection controls, bool dispose) { for (int ix = controls.Count - 1; ix >= 0; --ix) { if (dispose) { controls[ix].Dispose(); } else { controls.RemoveAt(ix); } } } //This snippet of code exposes the DoubleBuffered property of a datagridview. This //Had eliminated the flicker which would happen at every tick of the timer. //This code courtesy of http://bitmatic.com/c/fixing-a-slow-scrolling-datagridview public static void DoubleBufferedDatagrid(this DataGridView dgv, bool setting) { Type dgvType = dgv.GetType(); PropertyInfo pi = dgvType.GetProperty("DoubleBuffered", BindingFlags.Instance | BindingFlags.NonPublic); pi.SetValue(dgv, setting, null); } //Interleave multiple irregular lists https://stackoverflow.com/questions/10974376/interleaving-multiple-more-than-2-irregular-lists-using-linq public static IEnumerable> TransposeOverhanging(this IEnumerable> source) { var enumerators = source.Select(e => e.GetEnumerator()).ToArray(); try { T[] g; do { yield return g = enumerators .Where(e => e.MoveNext()).Select(e => e.Current).ToArray(); } while (g.Any()); } finally { Array.ForEach(enumerators, e => e.Dispose()); } } } }