/// <summary> /// The convert to. /// </summary> /// <param name="type"> /// The type. /// </param> /// <param name="value"> /// The value. /// </param> /// <param name="startIndex"> /// The start index. /// </param> /// <param name="length"> /// The length. /// </param> /// <returns> /// The <see cref="object"/> . /// </returns> public override object ConvertTo(Type type, byte[] value, int startIndex, int length) { if (type != typeof(string)) { throw new ArgumentException(string.Format("Ќевозможно выполнить преобразование в тип: {0}", type.Name), "value"); } var destinationArray = new byte[length]; Array.Copy(value, startIndex, destinationArray, 0, length); var array = new CBitArray(destinationArray); var i = (length * 8) / 6; var charArray = new char[i]; var index = 0; var num2 = 0; while (index < charArray.Length) { byte num3 = 0; num3 = (byte)(num3 | ((byte)(ToByte(array.Get(num2)) << 5))); num3 = (byte)(num3 | ((byte)(ToByte(array.Get(++num2)) << 4))); num3 = (byte)(num3 | ((byte)(ToByte(array.Get(++num2)) << 3))); num3 = (byte)(num3 | ((byte)(ToByte(array.Get(++num2)) << 2))); num3 = (byte)(num3 | ((byte)(ToByte(array.Get(++num2)) << 1))); num3 = (byte)(num3 | ToByte(array.Get(++num2))); num2++; charArray[index] = encodingBytes[num3]; index++; } return(new string(charArray, 0, charArray.Length)); }
/// <summary> /// The convert from. /// </summary> /// <param name="value"> /// The value. /// </param> /// <returns> /// The <see cref="byte"/> . /// </returns> public override byte[] ConvertFrom(object value) { base.ConvertFrom(value); if (value.GetType() != typeof(string)) { throw new ArgumentException( string.Format("Ќевозможно выполнить преобразование типа: {0}", value.GetType().Name), "value"); } var str = ((string)value).ToUpper(); var array = new CBitArray(); var num = 0; var index = 0; while (num < str.Length) { var key = str[num]; if (!encodingChars.ContainsKey(key)) { key = ' '; } var num3 = encodingChars[key]; array.Set(index, (num3 & 0x20) == 0x20); array.Set(++index, (num3 & 0x10) == 0x10); array.Set(++index, (num3 & 8) == 8); array.Set(++index, (num3 & 4) == 4); array.Set(++index, (num3 & 2) == 2); array.Set(++index, (num3 & 1) == 1); index++; num++; } return(array.ToArray()); }