|
|
@ -7,26 +7,24 @@ namespace FLocal.Core { |
|
|
|
|
|
|
|
|
|
|
|
public class Config<T> where T : Config<T> { |
|
|
|
public class Config<T> where T : Config<T> { |
|
|
|
|
|
|
|
|
|
|
|
private static Config<T> _instance; |
|
|
|
private static T _instance; |
|
|
|
|
|
|
|
|
|
|
|
public static Config<T> instance { |
|
|
|
public static T instance { |
|
|
|
get { |
|
|
|
get { |
|
|
|
if(_instance == null) throw new FLocalException("not initialized"); |
|
|
|
if(_instance == null) throw new FLocalException("not initialized"); |
|
|
|
return _instance; |
|
|
|
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<T> config) { |
|
|
|
protected static void doInit(Func<T> configCreator) { |
|
|
|
_instance = config; |
|
|
|
if(_instance != null) throw new FLocalException("already initialized"); |
|
|
|
|
|
|
|
lock(_instance) { |
|
|
|
|
|
|
|
if(_instance != null) throw new FLocalException("already initialized"); |
|
|
|
|
|
|
|
_instance = configCreator(); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|