using System;
using System.Collections.Generic;
using System.Configuration;
using System.Linq;
using System.Text;
namespace RainmeterStudio.UI.Controller
{
public static class SettingsProvider
{
///
/// Attempts to retrieve the setting of type T, where T is class
///
/// Any class type
/// Name of setting
/// Retrieved setting, or null if not found
public static T GetSetting (string name) where T : class
{
var property = Properties.Settings.Default.Properties
.OfType()
.FirstOrDefault(x => String.Equals(x.Name, name));
return (property == null) ? null : (property.DefaultValue as T);
}
///
/// Attempts to retrieve the setting of type T
///
/// Any type
/// Name of setting
/// Output value
/// True if attempt was successful
public static bool TryGetSetting(string name, out T value)
{
var property = Properties.Settings.Default.Properties.OfType().FirstOrDefault(x => x.Name.Equals(name));
if (property != null)
{
value = (T)property.DefaultValue;
return true;
}
else
{
value = default(T);
return false;
}
}
}
}