using System.Text.Json; namespace ExtensiblePortfolioSite { public static class Config { private static String ConfigFile = "eps_host_config.json"; public static void SetConfigFile(String File) { ConfigFile = File; } public static String Name { get; private set; } = "invalid"; public static String? Phone { get; private set; } = null; public static String? Email { get; private set; } = null; public static String[]? Description { get; private set; } = null; public static Dictionary Languages = new Dictionary() { { "C#", "https://seeklogo.com/images/C/c-sharp-c-logo-02F17714BA-seeklogo.com.png" }, { "Kotlin", "https://upload.wikimedia.org/wikipedia/commons/7/74/Kotlin_Icon.png" }, { "Lua", "https://upload.wikimedia.org/wikipedia/commons/c/cf/Lua-Logo.svg" }, { "C/C++", "https://upload.wikimedia.org/wikipedia/commons/1/19/C_Logo.png" }, }; public static void LoadConfig() { JsonDocument Doc = JsonDocument.Parse(File.ReadAllText(ConfigFile), new JsonDocumentOptions { AllowTrailingCommas = true, CommentHandling = JsonCommentHandling.Skip, MaxDepth = 16, }); foreach (JsonProperty property in Doc.RootElement.EnumerateObject()) { switch (property.Value.ValueKind) { case JsonValueKind.String: String value = property.Value.GetString()!; switch (property.Name) { case "Name": Config.Name = value; break; case "Phone": Config.Phone = value; break; case "Email": Config.Email = value; break; } break; case JsonValueKind.Array: switch (property.Name) { case "Description": Config.Description = new string[property.Value.GetArrayLength()]; var enumerator = property.Value.EnumerateArray(); for (int i = 0; i < property.Value.GetArrayLength(); i++) { if (!enumerator.MoveNext()) break; if (enumerator.Current.ValueKind == JsonValueKind.String) Config.Description[i] = enumerator.Current.GetString()!; } break; } break; case JsonValueKind.Object: break; case JsonValueKind.Number: break; case JsonValueKind.True: //Why, why isn't it called boolean break; } } } } }