public static void CopyProperty(this IVsWritableSettingsStore store, SettingsStoreProperty from, string toName)
        {
            ThreadHelper.ThrowIfNotOnUIThread();
            var fromName       = from.Name;
            var collectionPath = from.CollectionPath;

            switch (from.Type)
            {
            case __VsSettingsType.SettingsType_String:
                ErrorHandler.ThrowOnFailure(store.GetString(collectionPath, fromName, out var stringValue));
                ErrorHandler.ThrowOnFailure(store.SetString(collectionPath, toName, stringValue));
                break;

            case __VsSettingsType.SettingsType_Int:
                ErrorHandler.ThrowOnFailure(store.GetInt(collectionPath, fromName, out var intValue));
                ErrorHandler.ThrowOnFailure(store.SetInt(collectionPath, toName, intValue));
                break;

            case __VsSettingsType.SettingsType_Int64:
                ErrorHandler.ThrowOnFailure(store.GetInt64(collectionPath, fromName, out var longValue));
                ErrorHandler.ThrowOnFailure(store.SetInt64(collectionPath, toName, longValue));
                break;

            case __VsSettingsType.SettingsType_Binary:
                uint[] actualByteLength = { 0 };
                ErrorHandler.ThrowOnFailure(store.GetBinary(collectionPath, fromName, 0, null, actualByteLength));
                byte[] bytes = new byte[actualByteLength[0]];
                ErrorHandler.ThrowOnFailure(store.GetBinary(collectionPath, fromName, actualByteLength[0], bytes, actualByteLength));
                ErrorHandler.ThrowOnFailure(store.SetBinary(collectionPath, toName, actualByteLength[0], bytes));
                break;
            }
        }
        public byte[] ReadBytes(string name, byte[] defaultValue = null)
        {
            if (_settingsStore == null)
            {
                return(defaultValue);
            }
            var actualNumberOfBytes = new uint[1];

            _settingsStore.GetBinary(SettingsRoot, name, 0, null, actualNumberOfBytes);
            var value = new byte[actualNumberOfBytes[0]];

            _settingsStore.GetBinary(SettingsRoot, name, (uint)value.Length, value, actualNumberOfBytes);
            return(value);
        }
Ejemplo n.º 3
0
        public T Get <T>(string name)
        {
            int exists;

            _writableSettingsStore.CollectionExists(_collectionName, out exists);
            if (exists != 1)
            {
                throw new Exception("Property " + name + " does not exist.");
            }

            uint[] actualNumberOfBytes = new uint[1];
            _writableSettingsStore.GetBinary(_collectionName, name, 0, null, actualNumberOfBytes);
            byte[] data = new byte[actualNumberOfBytes[0]];
            _writableSettingsStore.GetBinary(_collectionName, name, (uint)data.Length, data, actualNumberOfBytes);

            BinaryFormatter binaryFormatter = new BinaryFormatter();

            binaryFormatter.AssemblyFormat = FormatterAssemblyStyle.Simple;
            MemoryStream memoryStream = new MemoryStream(data);

            return((T)binaryFormatter.Deserialize(memoryStream));
        }