You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
designPattern/DesignPattern/Singleton/Configuration.cs

35 lines
712 B

using Newtonsoft.Json.Linq;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Singleton
{
public sealed class Configuration
{
public static Configuration Settings { get; } = new Configuration();
private Dictionary<string, object> dict = new Dictionary<string, object>();
private Configuration()
{
LoadConfig();
}
private void LoadConfig()
{
string str = File.ReadAllText("config.json");
JObject jo = JObject.Parse(str);
foreach (KeyValuePair<string, JToken> kv in jo)
{
dict.Add(kv.Key, kv.Value);
}
}
public object this[string key] { get { return dict[key]; } }
}
}