3using Newtonsoft.Json.Linq;
70 public BadSettings(Dictionary<string, BadSettings> properties,
string sourcePath)
76 foreach (KeyValuePair<string, BadSettings> kvp
in m_Properties)
150 if (
m_Value?.Type == JTokenType.Array && !typeof(T).IsArray)
163 public void SetValue(JToken? value,
bool invokeOnChange =
true)
182 SetValue(value ==
null ? JValue.CreateNull() : JToken.FromObject(value));
272 if (setting.
GetValue() is JArray arr2)
274 foreach (JToken jToken
in arr2)
281 arr.Add(setting.
GetValue() ?? JValue.CreateNull());
331 string[] path = propertyPath.Split(
'.');
334 foreach (
string s
in path)
336 if (!current.HasProperty(s))
339 current.SetProperty(s, se);
358 string[] path = propertyPath.Split(
'.');
361 foreach (
string s
in path)
363 if (!current.HasProperty(s))
382 return GetValue()?.ToString() ??
"NULL";
385 StringBuilder sb =
new StringBuilder();
392 string str = s.
ToString().Replace(
"\n",
"\n\t");
393 sb.AppendLine($
" {propertyName}: {str}");
398 return sb.ToString();
414 for (
int i = 0; i < str.Length; i++)
416 if (str[i] !=
'$' || i + 1 >= str.Length || str[i + 1] !=
'(')
421 int end = str.IndexOf(
')', i + 2);
425 throw new Exception(
"Unclosed environment variable");
428 string envVar = str.Substring(i + 2, end - i - 2);
438 throw new Exception($
"Environment variable '{envVar}' not found");
442 str = str.Replace(str.Substring(i, end - i + 1), env);
468 string value = settings.
GetValue<
string>()!;
472 else if (settings.
HasValue<
string[]>())
474 string[] value = settings.
GetValue<
string[]>()!;
476 for (
int i = 0; i < value.Length; i++)
484 foreach (
string propertyName
in settings.PropertyNames)
Public Api for the Settings System.
readonly Dictionary< string, BadSettings > m_Properties
The properties of the Current Settings Object.
void Populate(bool invokeOnChanged, params BadSettings[] settings)
Populates the current object with the settings provided.
readonly string m_SourcePath
The Source Path of the Settings Object.
BadSettings? FindProperty(string propertyPath)
Finds a property based on the property path relative to this object.
JToken? m_Value
The Json Token of the Settings Object.
IEnumerable< string > PropertyNames
The Property Names of the Settings Object.
BadSettings(JToken? value, string sourcePath)
Creates a new Settings Object from a Json Token.
object? m_Cache
Cache for the Serialized Value of the Settings.
bool m_IsDirty
Indicates if the current object is dirty and needs to be re-serialized.
override string ToString()
Returns a string representation of the current object.
void SetProperty(string propertyName, BadSettings value, bool invokeOnChange=true)
Sets the Property with the given Name.
void SetValue(JToken? value, bool invokeOnChange=true)
Sets the Json Token of the Current Settings Object.
bool HasValue()
Returns true if the Settings Object has a JToken Value.
static void ResolveEnvironmentVariables(BadSettings root)
Resolves Environment Variables in the current object.
T? GetValue< T >()
Returns a Deserialized Value of the Settings Object.
static string ResolveEnvironmentVariables(BadSettings root, BadSettings parent, string str)
Resolves Environment Variables in the current object.
BadSettings(Dictionary< string, BadSettings > properties, string sourcePath)
Creates a new Settings Object from a Dictionary of Properties.
bool HasValue< T >()
Returns true if the Settings Object can be Deserialized into the given Type.
void InvokeValueChanged()
BadSettings GetProperty(string propertyName)
Returns the Property with the given Name.
void SetValue(object? value)
Sets the Json Token of the Current Settings Object.
JToken? GetValue()
Returns the Json Token of the Settings Object.
BadSettings FindOrCreateProperty(string propertyPath)
Finds a property based on the property path relative to this object.
BadSettings(string sourcePath)
Creates a new empty Settings Object.
bool HasProperty(string propertyName)
Returns true if the Settings Object has the given Property.
bool RemoveProperty(string propertyName, bool invokeOnChange=true)
Removes the Property with the given Name.
T? FindProperty< T >(string propertyName)
Finds a property based on the property path relative to this object.
static void ResolveEnvironmentVariables(BadSettings root, BadSettings settings, BadSettings parent)
Resolves Environment Variables in the current object.
void PropertyValueChanged()
Contains the Settings Implementation.