Пример #1
0
        private object GetValue(SettingEntryType type)
        {
            switch (type)
            {
            case SettingEntryType.UnicodeString:
                return(ByteArrayExtensions.ToTrimmedString(BinaryValue, Encoding.BigEndianUnicode));

            case SettingEntryType.Binary:
                return(BinaryValue);

            case SettingEntryType.DateTime:
                var buffer = new byte[8];
                Buffer.BlockCopy(NumericValue, 0, buffer, 0, 8);
                return(ByteArrayExtensions.ToDateTime(buffer));

            case SettingEntryType.Int32:
                return(BitConverter.ToInt32(GetNumericValue(0, 4), 0));

            case SettingEntryType.Int64:
                return(BitConverter.ToUInt64(GetNumericValue(0, 8), 0));

            case SettingEntryType.Float:
                return(BitConverter.ToSingle(GetNumericValue(0, 4), 0));

            case SettingEntryType.Double:
                return(BitConverter.ToDouble(GetNumericValue(0, 8), 0));

            default:
                throw new NotSupportedException("Invalid Type: " + type);
            }
        }
Пример #2
0
 public SettingEntry(OffsetTable offsetTable, BinaryContainer binary, int startOffset) : base(offsetTable, binary, startOffset)
 {
     _typeCache = Type;
     if (_typeCache == SettingEntryType.Binary || _typeCache == SettingEntryType.UnicodeString)
     {
         offsetTable["BinaryValue"].Length = GetValue <int>();
     }
 }
Пример #3
0
        private void SetValue(SettingEntryType type, object value)
        {
            //TODO: what if new length != old
            byte[] buffer;
            switch (type)
            {
            case SettingEntryType.UnicodeString:
            case SettingEntryType.Binary:
                buffer = type == SettingEntryType.UnicodeString
                                     ? Encoding.BigEndianUnicode.GetBytes((string)value)
                                     : (byte[])value;
                BinaryValue = buffer;
                SetValue(BinaryValue.Length);
                break;

            case SettingEntryType.DateTime:
                buffer = ByteArrayExtensions.FromDateTime((DateTime)value);
                Buffer.BlockCopy(buffer, 0, NumericValue, 0, 8);
                break;

            case SettingEntryType.Int32:
                SetNumericValue(BitConverter.GetBytes((int)value));
                break;

            case SettingEntryType.Int64:
                SetNumericValue(BitConverter.GetBytes((long)value));
                break;

            case SettingEntryType.Float:
                SetNumericValue(BitConverter.GetBytes((float)value));
                break;

            case SettingEntryType.Double:
                SetNumericValue(BitConverter.GetBytes((double)value));
                break;

            default:
                throw new NotSupportedException("Invalid Type: " + type);
            }
        }