private void SetValueFromType(string sourceStr, ConvarType type, out object value) { switch (type) { case ConvarType.Integer: value = int.Parse(sourceStr); break; case ConvarType.Boolean: value = bool.Parse(sourceStr); break; case ConvarType.List: value = sourceStr.Split(';'); break; case ConvarType.String: value = sourceStr; break; } value = null; }
private bool SetTypeAndValue(string sourceStr, out object value, out ConvarType type) { // The only thing this function can do is check for integer and boolean types. // Lists and strings could be interpreted as each other. int retInt = 0; bool retBool = false; string retString = string.Empty; string[] retArray = null; if (int.TryParse(sourceStr, out retInt)) { type = ConvarType.Integer; value = retInt; return true; } else if (bool.TryParse(sourceStr, out retBool)) { type = ConvarType.Boolean; value = retBool; return true; } else { retArray = sourceStr.Split(';'); if (retArray.Length > 1) { type = ConvarType.List; value = retArray; return true; } else { type = ConvarType.String; value = sourceStr; return true; } } }
public Convar(string name, string value, ConvarType type) { this.m_name = name; this.m_type = type; SetValueFromType(value, m_type, out m_value); }
public void SetValue(string value, ConvarType type) { this.m_type = type; SetValueFromType(value, m_type, out m_value); }
public void SetConfigValue(string name, string value, ConvarType type) { for (int i = 0; i < m_convars.Count; i++) { if (m_convars[i].Name == name) { m_convars[i].SetValue(value, type); break; } } }