using System; using System.Collections.Generic; using System.Threading; using System.Threading.Tasks; using System.Windows.Forms; namespace DSPRE { public static class Extensions { public static int IndexOfNumber(this string str) { return str.IndexOfAny("0123456789".ToCharArray()); } public static bool ContainsNumber(this string str) { return str.IndexOfNumber() > 0; } public static Dictionary Reverse (this Dictionary source) { var dictionary = new Dictionary(StringComparer.InvariantCultureIgnoreCase); foreach (var entry in source) { string newKey = entry.Value; if (!dictionary.ContainsKey(newKey)) { dictionary.Add(newKey, entry.Key); } } return dictionary; } public static void FadeIn(this Form o, int framelength = 16, int frames = 10) { //Object is not fully invisible. Fade it in while (o != null && !o.IsDisposed && o.Opacity < 1.0) { Thread.Sleep(framelength); o.Opacity += (1.0 / frames); } o.Opacity = 1; //make fully visible } public static void FadeOut(this Form o, int framelength = 16, int frames = 10) { //Object is fully visible. Fade it out while (o != null && o.Opacity > 0.0) { Thread.Sleep(framelength); o.Opacity -= (1.0 / frames); } o.Opacity = 0; //make fully invisible Console.WriteLine("Fadeout done"); } //public static Dictionary Reverse(this IDictionary source) { // var dictionary = new Dictionary(); // foreach (var entry in source) { // if (!dictionary.ContainsKey(entry.Value)) { // dictionary.Add(entry.Value, entry.Key); // } // } // return dictionary; //} } }