/// <summary> /// Attempts to get the array field with the specified name. /// </summary> /// <typeparam name="T"></typeparam> /// <param name="name"></param> /// <returns></returns> public T[] GetArrayValue <T>(string name) { Entry entry = this.GetValue(name); if (entry.ParsedType != Entry.TomlType.Array) { throw new InvalidOperationException("Specified value is not an array"); } // TODO: MAKE MULTI-DIMENSION ARRAYS WORK. var arrayEntry = (Toml.Array)entry; //if (typeof(T).IsArray) //{ // return GetArrayValue(typeof(T).GetElementType(), name); //} //if (typeof(T).Equals(typeof(object))) //{ // return arrayEntry.Children // .Select(c => c.SourceText) // .Select(val => TypeParsers.Parse(arrayEntry.GetArrayType(), val)) // .ToArray(); //} return(arrayEntry.Children .Select(c => c.SourceText) .Select(val => TypeParsers.Parse <T>(val)) .ToArray()); }
/// <summary> /// Attempts to find the field with the specified /// </summary> /// <typeparam name="T"></typeparam> /// <param name="name"></param> /// <returns></returns> public T GetFieldValue <T>(string name) { string value = null; if (TryGetValue(name, out value)) { return(TypeParsers.Parse <T>(value)); } throw new KeyNotFoundException("Specified value was not found"); }
/// <summary> /// Attempts to find the field with the specified name. /// </summary> /// <typeparam name="T"></typeparam> /// <param name="name"></param> /// <returns>true if the named value can be found and parsed as the requested type, otherwise false.</returns> public bool TryGetFieldValue <T>(string name, out T result) { result = default(T); string value = null; if (TryGetValue(name, out value)) { return(TypeParsers.TryParse(value, out result)); } return(false); }