public static TomlValue Path(this TomlTable value, String path) { TPath tpath = new TPathParser(new Lexer(path, "").GetTokens()).Parse(); return(tpath.Eval(value)); }
public static T Path <T>(this TomlTable value, String path) { var result = value.Path(path); try { if (typeof(T) == typeof(DateTime)) { return((T)Convert.ChangeType(result.AsDateTime(), typeof(T))); } if (typeof(T) == typeof(DateTimeOffset)) { return((T)Convert.ChangeType(result.AsDateTimeOffset(), typeof(T))); } if (typeof(T) == typeof(String)) { return((T)Convert.ChangeType(result.AsString(), typeof(T))); } if (typeof(T) == typeof(Int32)) { return((T)Convert.ChangeType(result.AsInt(), typeof(T))); } if (typeof(T) == typeof(Int64)) { return((T)Convert.ChangeType(result.AsInt(), typeof(T))); } if (typeof(T) == typeof(Single)) { return((T)Convert.ChangeType(result.AsDouble(), typeof(T))); } if (typeof(T) == typeof(Double)) { return((T)Convert.ChangeType(result.AsDouble(), typeof(T))); } if (typeof(T) == typeof(Boolean)) { return((T)Convert.ChangeType(result.AsBoolean(), typeof(T))); } if (typeof(T) == typeof(Int32[])) { return((T)Convert.ChangeType(result.AsList().Select(i => (Int32)i.AsInt()).ToArray(), typeof(T))); } if (typeof(T) == typeof(Int64[])) { return((T)Convert.ChangeType(result.AsList().Select(i => (Int64)i.AsInt()).ToArray(), typeof(T))); } if (typeof(T) == typeof(Single[])) { return((T)Convert.ChangeType(result.AsList().Select(i => (Single)i.AsDouble()).ToArray(), typeof(T))); } if (typeof(T) == typeof(Double[])) { return((T)Convert.ChangeType(result.AsList().Select(i => i.AsDouble()).ToArray(), typeof(T))); } if (typeof(T) == typeof(Boolean[])) { return((T)Convert.ChangeType(result.AsList().Select(i => i.AsBoolean()).ToArray(), typeof(T))); } if (typeof(T) == typeof(String[])) { return((T)Convert.ChangeType(result.AsList().Select(i => i.AsString()).ToArray(), typeof(T))); } if (typeof(T) == typeof(TomlValue[])) { return((T)Convert.ChangeType(result.AsList().ToArray(), typeof(T))); } return((T)Convert.ChangeType(result, typeof(T))); } catch (InvalidCastException) { return(default(T)); } }
public TomlDottedTable(TomlTable parent, String name) : base(name) { this.parent = parent; }