protected override bool TryGetValue(MyIniValue storage, out Dictionary <string, Vector3D> value) { value = new Dictionary <string, Vector3D>(); List <string> lines = new List <string>(); storage.GetLines(lines); foreach (string l in lines) { if (string.IsNullOrWhiteSpace(l)) { continue; } string [] configValues = l.Split(new [] { ' ' }, StringSplitOptions.RemoveEmptyEntries); if (configValues.Length != 4) { return(false); } Vector3D offset = new Vector3D(); if (!double.TryParse(configValues [1], out offset.X)) { return(false); } if (!double.TryParse(configValues [2], out offset.Y)) { return(false); } if (!double.TryParse(configValues [3], out offset.Z)) { return(false); } value[configValues [0]] = offset; } return(value.Count > 0); }
/// <summary>Returns the value requested and throws if it does not exist.</summary> /// <param name="ini">This</param> /// <param name="section">Name of the section</param> /// <param name="key">Key</param> /// <returns>The value corresponding to the key in the section</returns> public static MyIniValue GetThrow(this MyIni ini, string section, string key) { MyIniValue res = ini.Get(section, key); if (res.IsEmpty) { throw new InvalidOperationException($"Need key '{key}' in section '{section}' in custom data"); } return(res); }
protected override bool TryGetValue(MyIniValue storage, out T value) { value = default(T); string temp; if (!storage.TryGetString(out temp)) { return(false); } return(Enum.TryParse <T>(temp, out value)); }
private bool getOrAddIniInt(string section, string key, ref int val, string description = "\n") { MyIniValue iniVal = param_ini.Get(section, key); if (iniVal.IsEmpty) { param_ini.Set(section, key, val); param_ini.SetComment(section, key, description); return(true); } val = iniVal.ToInt32(); return(false); }
protected override bool TryGetValue(MyIniValue storage, out Vector3D value) { value = new Vector3D(); string temp; if (!storage.TryGetString(out temp)) { return(false); } string [] args = temp.Split(new [] { ' ' }, StringSplitOptions.RemoveEmptyEntries); if (args.Length != 3) { return(false); } if (!double.TryParse(args [0], out value.X)) { return(false); } if (!double.TryParse(args [1], out value.Y)) { return(false); } return(double.TryParse(args [2], out value.Z)); }
protected override bool TryGetValue(MyIniValue storage, out bool value) { return(storage.TryGetBoolean(out value)); }
protected abstract bool TryGetValue(MyIniValue storage, out T value);
protected override bool TryGetValue(MyIniValue storage, out double value) { return(storage.TryGetDouble(out value)); }
protected override bool TryGetValue(MyIniValue storage, out int value) { return(storage.TryGetInt32(out value)); }
protected override bool TryGetValue(MyIniValue storage, out string value) { return(storage.TryGetString(out value)); }