public static bool SwitchText(IntPtr hWnd, Language layout, TextReplaceMethod rm) { bool success = false; string text; IDictionary <string, object> backup = null; if ((rm & TextReplaceMethod.UseClipboard) != 0) { backup = GetClipboardData(); var oldId = WinApi.GetClipboardSequenceNumber(); text = GetText(hWnd, rm); var newId = WinApi.GetClipboardSequenceNumber(); if (oldId == newId) { return(success); } } else { text = GetText(hWnd, rm); } if (!(string.IsNullOrWhiteSpace(text) || rm == TextReplaceMethod.Devenv && DevenvFix(text))) { var convText = ConvertText(text, layout); SetText(convText, hWnd, rm); success = true; } if ((rm & TextReplaceMethod.UseClipboard) != 0) { SetClipboardData(backup); } return(success); }