Developer, Former MVP, now at Microsoft - Best of 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011, 2012, 2013
[assembly: System.Diagnostics.DebuggerVisualizer( typeof(EncodingVisualizer.StringBytes), Target = typeof(System.String), Description = "Encoding Viewer")]
using Microsoft.VisualStudio.DebuggerVisualizers; namespace EncodingVisualizer { public class StringBytes : DialogDebuggerVisualizer { protected override void Show(IDialogVisualizerService windowService, IVisualizerObjectProvider objectProvider) { string s = (string)objectProvider.GetObject(); frmStringBytes f = new frmStringBytes(s); f.ShowDialog(); } } }
public frmStringBytes(string aString) : this() { txtExpression.Text = aString; string s; byte[] arr; arr = System.Text.Encoding.ASCII.GetBytes(aString); s = "ASCII = " + BitConverter.ToString(arr); s += "\r\n\r\n"; arr = System.Text.Encoding.Unicode.GetBytes(aString); s += "Unicode = " + BitConverter.ToString(arr); s += "\r\n\r\n"; arr = System.Text.Encoding.Default.GetBytes(aString); s += "Default = " + BitConverter.ToString(arr) + "\r\n"; // Do other encodings here e.g UTF7, UTF8, UTF32 etc txtValue.Text = s; }