public unsafe object Convert(object value, Type targetType, object parameter, CultureInfo culture)
        {
            KStudioMetadataValueBuffer buffer = value as KStudioMetadataValueBuffer;

            StringBuilder sb = new StringBuilder();

            if (buffer != null)
            {
                uint     size;
                GCHandle handle;
                buffer.AccessUnderlyingDataBuffer(out size, out handle);
                IntPtr ptr = handle.AddrOfPinnedObject();
                byte * p   = (byte *)ptr.ToPointer();

                for (uint i = 0; i < size; ++i)
                {
                    sb.Append(p[i].ToString("X2", CultureInfo.InvariantCulture));
                    sb.Append(" ");
                }
            }
            else
            {
                KStudioInvalidMetadataValue invalid = value as KStudioInvalidMetadataValue;

                if (invalid != null)
                {
                    foreach (byte b in invalid.Data)
                    {
                        sb.Append(b.ToString("X2", CultureInfo.InvariantCulture));
                        sb.Append(" ");
                    }
                }
            }

            value = sb.ToString();

            return(value);
        }
        public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
        {
            string str = value as string;

            value = null;

            if (str != null)
            {
                str = str + "\n";

                byte[] temp = new byte[str.Length];

                int  i         = 0;
                char?firstByte = null;

                foreach (char ch in str)
                {
                    char ch2 = Char.ToLowerInvariant(ch);

                    if (Char.IsDigit(ch2) || (('a' <= ch2) && ('f' >= ch2)))
                    {
                        if (firstByte.HasValue)
                        {
                            byte b;
                            if (byte.TryParse(firstByte.Value.ToString() + ch2, NumberStyles.AllowHexSpecifier, null, out b))
                            {
                                temp[i] = b;
                                ++i;
                                firstByte = null;
                            }
                        }
                        else
                        {
                            firstByte = ch;
                        }
                    }
                    else
                    {
                        if (firstByte.HasValue)
                        {
                            byte b;
                            if (byte.TryParse(firstByte.Value.ToString(), NumberStyles.AllowHexSpecifier, null, out b))
                            {
                                temp[i] = b;
                                ++i;
                                firstByte = null;
                            }
                        }
                    }
                }

                if (i > 0)
                {
                    byte[] final = new byte[i];
                    Array.Copy(temp, final, i);
                    value = new KStudioMetadataValueBuffer(final);
                }
            }

            if (value == null)
            {
                // no empty data
                value = new KStudioMetadataValueBuffer(new byte[] { 0 });
            }

            return(value);
        }