Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- namespace FF_AccessLib
- {
- public class FF_Properties
- {
- //Main Class Implimentation
- FF_Properties()
- {
- //if (!File.Exists("Settings.json"))
- // CreateFile();
- //LoadJson();
- Properties = new PropData();
- Properties.DB_Host = "127.0.0.1";
- Properties.DB_Port = "3311";
- Properties.DB_User = "root";
- Properties.DB_Password = "root";
- }
- private void CreateFile()
- {
- List<PropData> _data = new List<PropData>();
- _data.Add(new PropData()
- {
- DB_Host = "127.0.0.1",
- DB_Port = "3311",
- DB_User = "root",
- DB_Password = "root"
- });
- string json = JsonConvert.SerializeObject(_data.ToArray());
- System.IO.File.WriteAllText("../../../Settings.json", json);
- }
- private void LoadJson()
- {
- if (!File.Exists("../../../Settings.json"))
- CreateFile();
- using (StreamReader r = new StreamReader("../../../Settings.json"))
- {
- string json = r.ReadToEnd();
- List<PropData> items = JsonConvert.DeserializeObject<List<PropData>>(json);
- Properties = items[0];
- }
- }
- private PropData Properties { get; set; }
- //Class Data
- public class PropData
- {
- public string DB_Host { get; set; }
- public string DB_Port { get; set; }
- public string DB_User { get; set; }
- public string DB_Password { get; set; }
- }
- //Singleton Functions
- private static FF_Properties instance;
- public static string Get(string propName)
- {
- if (instance == null)
- {
- instance = new FF_Properties();
- }
- string temp = "";
- try
- {
- temp = (string)instance.Properties.GetType().GetProperty(propName).GetValue(instance.Properties);
- }
- catch { }
- return temp;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement