private static void LoadConfigurationPrefixed(JsonObject content, string prefix) { foreach (var value in content) { switch (value.Value.ValueType) { case JsonValueType.Boolean: { ConfigurationValue <bool> configuration_value = get <bool>(prefix + value.Key); configuration_value.Set(value.Value.GetBoolean()); } break; case JsonValueType.Number: { ConfigurationValue <int> configuration_value = get <int>(prefix + value.Key); configuration_value.Set((int)value.Value.GetNumber()); } break; case JsonValueType.Object: { LoadConfigurationPrefixed(value.Value.GetObject(), prefix + value.Key + '.'); } break; case JsonValueType.Array: { ConfigurationTable <int> configuration_table = getTable <int>(prefix + value.Key); configuration_table.Clear(); foreach (var item in value.Value.GetArray()) { configuration_table.Add((int)item.GetNumber()); } } break; default: break; } } }
private static void Initialize() { Assembly assembly = typeof(ConfigurationManager).GetTypeInfo().Assembly; foreach (TypeInfo type in assembly.DefinedTypes) { foreach (var field in type.DeclaredFields) { if (field.IsStatic) { var attribute = field.GetCustomAttribute <Configuration>(); if (attribute != null) { switch (field.FieldType.Name) { case "Int32": { ConfigurationValue <int> value = create <int>(attribute.Name, attribute.Description); value.Set((int)field.GetValue(null)); value.AddField(field); } break; case "Single": { ConfigurationValue <float> value = create <float>(attribute.Name, attribute.Description); value.Set((float)field.GetValue(null)); value.AddField(field); } break; case "Boolean": { ConfigurationValue <bool> value = create <bool>(attribute.Name, attribute.Description); value.Set((bool)field.GetValue(null)); value.AddField(field); } break; case "List`1": { var createTable = GetCreateTable(field.FieldType.GenericTypeArguments[0]); ConfigurationValueBase table = (ConfigurationValueBase)createTable.Invoke(null, new object[] { attribute.Name, attribute.Description }); var getter = table.GetType().GetRuntimeMethod("Get", new Type[] { }); field.SetValue(null, getter.Invoke(table, null)); } break; default: break; } } } } } }