Webiant Logo Webiant Logo
  1. No results found.

    Try your search with a different keyword or use * as a wildcard.

AppSettings.cs

using Newtonsoft.Json;
using Newtonsoft.Json.Linq;

namespace Nop.Core.Configuration;

/// 
/// Represents the app settings
/// 
public partial class AppSettings
{
    #region Fields

    protected readonly Dictionary _configurations;

    #endregion

    #region Ctor

    public AppSettings(IList configurations = null)
    {
        _configurations = configurations
                              ?.OrderBy(config => config.GetOrder())
                              ?.ToDictionary(config => config.GetType(), config => config)
                          ?? new Dictionary();
    }

    #endregion
        
    #region Methods

    /// 
    /// Get configuration parameters by type
    /// 
    /// Configuration type
    /// Configuration parameters
    public TConfig Get() where TConfig : class, IConfig
    {
        if (_configurations[typeof(TConfig)] is not TConfig config)
            throw new NopException($"No configuration with type '{typeof(TConfig)}' found");

        return config;
    }

    /// 
    /// Update app settings
    /// 
    /// Configurations to update
    public void Update(IList configurations)
    {
        foreach (var config in configurations)
        {
            _configurations[config.GetType()] = config;
        }
    }

    #endregion

    #region Properties

    /// 
    /// Gets or sets raw configuration parameters
    /// 
    [JsonExtensionData]
    public Dictionary Configuration { get; set; }

    #endregion
}