#region Apache License 2.0
/*
Nuclex .NET Framework
Copyright (C) 2002-2024 Markus Ewald / Nuclex Development Labs
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
#endregion // Apache License 2.0
using System;
using System.Collections.Generic;
namespace Nuclex.Support.Settings {
/// Interface by which settings and configuration data can be accessed
///
///
/// The intended usage pattern for options is for your application to simply read and
/// write whatever options it needs using the type it expects them to be.
///
///
/// When you enumerate the options appearing under a category, the settings store will
/// try to guess the likely type of an option, but this is not always accurate. For
/// example, assigning the text 'true' to an option in a .cfg or .ini file could mean
/// that the option is a boolean or it could simply be a coincidence. When you read
/// this value as a boolean, the settings store will correctly convert it to a boolean,
/// when you read it as a string, you will get back "true" in plain text.
///
///
/// Which types of values a settings store can accept can also change between different
/// settings store implementations. The windows registry supports string and byte
/// arrays whereas configuration files have no standardized way of holding these.
/// Any property store must support a minimal subset including booleans, integers,
/// floating point values and strings.
///
///
public interface ISettingsStore {
/// Enumerates the categories defined in the configuration
/// An enumerable list of all used categories
IEnumerable EnumerateCategories();
/// Enumerates the options stored under the specified category
/// Category whose options will be enumerated
/// An enumerable list of all options in the category
IEnumerable EnumerateOptions(string category = null);
/// Retrieves the value of the specified option
/// Type the option will be converted to
/// Category the option can be found in. Can be null.
/// Name of the option that will be looked up
/// The value of the option with the specified name
TValue Get(string category, string optionName);
/// Tries to retrieve the value of the specified option
/// Type the option will be converted to
/// Category the option can be found in. Can be null.
/// Name of the option that will be looked up
/// Will receive the value of the option, if found
///
/// True if the option existed and its value was written into the
/// parameter, false otherwise
///
bool TryGet(string category, string optionName, out TValue value);
/// Saves an option in the settings store
/// Type of value that will be saved
/// Category the option will be placed in. Can be null.
/// Name of the option that will be saved
/// The value under which the option will be saved
void Set(string category, string optionName, TValue value);
/// Removes the option with the specified name
/// Category the option is found in. Can be null.
/// Name of the option that will be removed
/// True if the option was found and removed
bool Remove(string category, string optionName);
}
} // namespace Nuclex.Support.Settings
#if WANT_TO_SUPPORT_MESSED_UP_CONFIGURATION_FILES
///
/// Some settings stores allow multiple options with the same name to exist.
/// If you request a collection of values (IEnumerable, ICollection, IList or their
/// generic variants), you will be given a collection of all values appearing
/// in the scope you specified.
///
#endif