using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Collections.Specialized; namespace Web.Core { public abstract class Config : IDisposable where T : Config { private static T _instance = null; public static T instance { get { if(_instance == null) throw new FLocalException("not initialized"); return _instance; } } protected Config() { } protected static void doInit(Func configCreator) { if(_instance != null) throw new FLocalException("already initialized"); lock(typeof(Config)) { if(_instance != null) throw new FLocalException("already initialized"); _instance = configCreator(); } } /*protected static void doReInit(Func configCreator) { lock(typeof(Config)) { _instance = configCreator(); } } public static bool isInitialized { get { return _instance != null; } }*/ public virtual void Dispose() { } protected static bool parseBool(string value) { switch(value.ToLower().Trim()) { case "1": case "true": case "on": case "enabled": case "yes": return true; case "0": case "false": case "off": case "disabled": case "no": return false; default: throw new CriticalException("Cannot parse '" + value + "'"); } } } }