using System; using System.Linq; using System.Windows.Forms; namespace GUIDacious { public partial class GuidForm : Form { private Guid _currentGuid; private Guid CurrentGuid { get => _currentGuid; set { _currentGuid = value; RefreshView(); } } public GuidForm() { InitializeComponent(); NewGuid(); } private string ComponentsString(bool upperCase = false) { // Byte counts per components: 4, 2, 2, 1, 1, 1, 1, 1, 1, 1, 1 var bytes = CurrentGuid.ToByteArray(); var c0 = BitConverter.ToString(bytes.Take(4).ToArray()).Replace("-", ""); var c1 = BitConverter.ToString(bytes.Skip(4).Take(2).ToArray()).Replace("-", ""); var c2 = BitConverter.ToString(bytes.Skip(6).Take(2).ToArray()).Replace("-", ""); var result = $"0x{c0}, 0x{c1}, 0x{c2}, 0x{bytes[8]:x2}, 0x{bytes[9]:x2}, 0x{bytes[10]:x2}, 0x{bytes[11]:x2}, 0x{bytes[12]:x2}, 0x{bytes[13]:x2}, 0x{bytes[14]:x2}, 0x{bytes[15]:x2}"; return upperCase ? result.ToUpper().Replace("X", "x") : result.ToLower(); } private void CopyButton_Click(object sender, EventArgs e) => Clipboard.SetText(GuidFormatBox.Text); private void Format_CheckedChanged(object sender, EventArgs e) => RefreshView(); private void NewGuid() => CurrentGuid = Guid.NewGuid(); private void NewGuidButton_Click(object sender, EventArgs e) => NewGuid(); private void RefreshView() { CurrentGuidDisplay.Text = CurrentGuid.ToString(); if(FormatStringLower.Checked) { GuidFormatBox.Text = CurrentGuid.ToString(); } else if(FormatStringUpper.Checked) { GuidFormatBox.Text = CurrentGuid.ToString().ToUpper(); } else if(FormatComponentsLower.Checked) { GuidFormatBox.Text = ComponentsString(); } else if(FormatComponentsUpper.Checked) { GuidFormatBox.Text = ComponentsString(true); } else if(FormatNewGuid.Checked) { GuidFormatBox.Text = $"new Guid({ComponentsString()});"; } } } }