From 87849291b8308850e15b6dd72af5b76de363d274 Mon Sep 17 00:00:00 2001 From: inga-lovinde <52715130+inga-lovinde@users.noreply.github.com> Date: Sun, 6 Jun 2010 07:52:38 +0000 Subject: [PATCH] Common.Config initial commit --- Common/Common.csproj | 1 + Core/Config.cs | 20 +++++++++----------- 2 files changed, 10 insertions(+), 11 deletions(-) diff --git a/Common/Common.csproj b/Common/Common.csproj index 6480322..b276843 100644 --- a/Common/Common.csproj +++ b/Common/Common.csproj @@ -45,6 +45,7 @@ + diff --git a/Core/Config.cs b/Core/Config.cs index a9cceeb..bbd14d9 100644 --- a/Core/Config.cs +++ b/Core/Config.cs @@ -7,26 +7,24 @@ namespace FLocal.Core { public class Config where T : Config { - private static Config _instance; + private static T _instance; - public static Config instance { + public static T instance { get { if(_instance == null) throw new FLocalException("not initialized"); return _instance; } - private set { - lock(_instance) { - if(_instance != null) throw new FLocalException("already initialized"); - _instance = value; - } - } } - private Config() { + protected Config() { } - public static void doInit(Config config) { - _instance = config; + protected static void doInit(Func configCreator) { + if(_instance != null) throw new FLocalException("already initialized"); + lock(_instance) { + if(_instance != null) throw new FLocalException("already initialized"); + _instance = configCreator(); + } } }