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