OleViewDotNet.COMRegistryViewer.CopyGuidToClipboard C# (CSharp) Method

CopyGuidToClipboard() private method

private CopyGuidToClipboard ( System.Guid guid, CopyGuidType copyType ) : void
guid System.Guid
copyType CopyGuidType
return void
        private void CopyGuidToClipboard(Guid guid, CopyGuidType copyType)
        {
            string strCopy = null;

            switch (copyType)
            {
                case CopyGuidType.CopyAsObject:
                    strCopy = String.Format("<object id=\"obj\" classid=\"clsid:{0}\">NO OBJECT</object>",
                        guid.ToString());
                    break;
                case CopyGuidType.CopyAsString:
                    strCopy = guid.ToString("B");
                    break;
                case CopyGuidType.CopyAsStructure:
                    {
                        MemoryStream ms = new MemoryStream(guid.ToByteArray());
                        BinaryReader reader = new BinaryReader(ms);
                        strCopy = "struct GUID guidObject = { ";
                        strCopy += String.Format("0x{0:X08}, 0x{1:X04}, 0x{2:X04}, {{", reader.ReadUInt32(),
                            reader.ReadUInt16(), reader.ReadUInt16());
                        for (int i = 0; i < 8; i++)
                        {
                            strCopy += String.Format("0x{0:X02}, ", reader.ReadByte());
                        }
                        strCopy += "}};";
                    }
                    break;
                case CopyGuidType.CopyAsHexString:
                    {
                        byte[] data = guid.ToByteArray();
                        strCopy = String.Join(" ", data.Select(b => String.Format("{0:X02}", b)));                        
                    }
                    break;                
            }

            if (strCopy != null)
            {
                Clipboard.SetText(strCopy);
            }
        }

Usage Example

 private void CopyGuid(COMRegistryViewer.CopyGuidType copy_type)
 {
     if (listViewTypes.SelectedItems.Count > 0)
     {
         ListViewItemWithIid item = (ListViewItemWithIid)listViewTypes.SelectedItems[0];
         COMRegistryViewer.CopyGuidToClipboard(item.Iid, copy_type);
     }
 }
All Usage Examples Of OleViewDotNet.COMRegistryViewer::CopyGuidToClipboard