CapyKit Documentation
  • Introduction
  • Getting Started
  • API Reference
    • CapyKit
      • CapyEventArgs
      • CapyEventHandler
      • CapyEventReporter
      • Color
      • EncryptedValue<T>
      • EventLevel
      • IPasswordAlgorithm
      • NamedColor
      • Password
      • Pbkdf2Algorithm
      • PoolItem<T>
      • Pool<T>
      • PropertyComparer<T, U>
    • CapyKit.Attributes
      • EnumerationAttribute<T>
      • EnumerationDescriptionAttribute
      • ValueFormatAttribute
    • CapyKit.Enumerations
      • MeasurementSystem
    • CapyKit.Extensions
      • EnumerationExtensions
      • LINQExtensions
      • ObjectExtensions
      • StringExtensions
    • CapyKit.Helpers
      • CalculationHelper
      • CompressionHelper
      • EncryptionHelper
      • IEncryptionAlgorithm
      • KeyHelper
      • LanguageHelper
      • SecurityHelper
      • SerializationHelper
      • SettingsHelper
      • ValidCharacterCollection
Search Results for

    Show / Hide Table of Contents
    • Introduction
    • Getting Started
    • API Reference
      • CapyKit
        • CapyEventArgs
        • CapyEventHandler
        • CapyEventReporter
        • Color
        • EncryptedValue<T>
        • EventLevel
        • IPasswordAlgorithm
        • NamedColor
        • Password
        • Pbkdf2Algorithm
        • PoolItem<T>
        • Pool<T>
        • PropertyComparer<T, U>
      • CapyKit.Attributes
        • EnumerationAttribute<T>
        • EnumerationDescriptionAttribute
        • ValueFormatAttribute
      • CapyKit.Enumerations
        • MeasurementSystem
      • CapyKit.Extensions
        • EnumerationExtensions
        • LINQExtensions
        • ObjectExtensions
        • StringExtensions
      • CapyKit.Helpers
        • CalculationHelper
        • CompressionHelper
        • EncryptionHelper
        • IEncryptionAlgorithm
        • KeyHelper
        • LanguageHelper
        • SecurityHelper
        • SerializationHelper
        • SettingsHelper
        • ValidCharacterCollection

    Class SettingsHelper

    Static class containing helper methods for retrieving and setting application settings.

    Inheritance
    object
    SettingsHelper
    Namespace: CapyKit.Helpers
    Assembly: CapyKit.dll
    Syntax
    public static class SettingsHelper
    Remarks

    The specific means of accessing and storing the settings are determined by the consumer, allowing for flexibility in various environments such as App.config or Web.config .

    Examples

    This example demonstrates how to set up the SettingsHelper class with custom accessor and detector methods that read from an App.config file. The setup is done at the beginning of the application execution, before any other usage of the helper methods.

    public int main(string[] args)
    {
       // Set up SettingsHelper with custom accessor and detector methods
       Func<string, object> accessor = (key) =>
       {
           Configuration config = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
           return config.AppSettings.Settings[key].Value;
       };
    
       Func<string, bool> detector = (key) =>
       {
           Configuration config = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
           return config.AppSettings.Settings.AllKeys.Contains(key);
       };
    
       SettingsHelper.SetAccessorMethod(accessor);
       SettingsHelper.SetDetectorMethod(detector);
    
       // Use the helper to retrieve and set settings
       SettingsHelper.SetApplicationSetting<int>("MySettingKey", 42);
       int newSetting = SettingsHelper.GetApplicationSetting<int>("MySettingKey");
       Console.WriteLine("New setting: {0}", newSetting);
    
       int mySetting = SettingsHelper.GetApplicationSetting<int>("MySettingKey");
       Console.WriteLine("Retrieved setting: {0}", mySetting);
    }

    Methods

    GetApplicationSetting<T>(string)

    Retrieves a setting with the given key.

    Declaration
    public static T GetApplicationSetting<T>(string settingName)
    Parameters
    Type Name Description
    string settingName

    The name of the setting to retrieve.

    Returns
    Type Description
    T

    The value of the setting as an uncast T.

    Type Parameters
    Name Description
    T

    The type of the setting to be retrieved.

    SetAccessorMethod(Func<string, object>)

    Sets the function used to retrieve application settings.

    Declaration
    public static void SetAccessorMethod(Func<string, object> accessor)
    Parameters
    Type Name Description
    Func<string, object> accessor

    The new function used to retrieve application settings.

    Exceptions
    Type Condition
    ArgumentNullException

    Thrown when one or more required arguments are null.

    SetDetectorMethod(Func<string, bool>)

    Sets the function used to detect if an application setting with a given key exists.

    Declaration
    public static void SetDetectorMethod(Func<string, bool> detector)
    Parameters
    Type Name Description
    Func<string, bool> detector

    The new function used to detect if an application setting exists.

    Exceptions
    Type Condition
    ArgumentNullException

    Thrown when one or more required arguments are null.

    In this article
    Back to top Generated by DocFX