示例#1
0
        /// <summary>
        /// Recherche d'un paramètre de configuration.
        /// </summary>
        /// <typeparam name="ValueT">Type de la valeur du paramètre.</typeparam>
        /// <param name="key">Nom du paramètre.</param>
        /// <param name="configurationName">Nom de la configuration.</param>
        /// <returns>Valeur du paramètre.</returns>
        public ValueT GetParameterValue <ValueT>(string key, string configurationName = IApplicationConfigurationService.DEFAULT_CONFIGURATION_NAME)
        {
            // Contrôle de la configuration ciblée.
            if (!configurationsContainer.ContainsKey(configurationName))
            {
                throw new ArgumentException($"The configuration '{configurationName}' is not registered");
            }
            IApplicationConfiguration currentConfiguration = configurationsContainer[configurationName];

            currentConfiguration.EnsureIsLoaded();

            // Contrôle des paramètres.
            if (!currentConfiguration.Parameters.ContainsKey(key))
            {
                throw new ArgumentException($"The configuration element {key} is not founnd.");
            }
            if (currentConfiguration.Parameters[key].GetElementType() != typeof(ValueT))
            {
                throw new ArgumentException($"Mismatch type between the requested type {typeof(ValueT)} and the configuration type {configurationsContainer[configurationName].Parameters[key].GetElementType()}.");
            }

            return((ValueT)currentConfiguration.Parameters[key].Value);
        }