public static void Type(this IOleCommandTarget target, string text) { var guid = VSConstants.VSStd2K; var variantMem = Marshal.AllocCoTaskMem(Marshal.SizeOf(typeof(VARIANT))); try { for (int i = 0; i < text.Length; i++) { switch (text[i]) { case '\r': target.Enter(); break; case '\t': target.Tab(); break; default: Marshal.GetNativeVariantForObject((ushort)text[i], variantMem); target.Exec( ref guid, (int)VSConstants.VSStd2KCmdID.TYPECHAR, 0, variantMem, IntPtr.Zero ); break; } } } finally { Marshal.FreeCoTaskMem(variantMem); } }