internal override void SetQuery <T>(TagQuery query, T val, bool bypassCheck) { TagQueryToken token = null; if (!bypassCheck) { token = query.Next(); if (token != null && !token.Name.Equals(Name)) { return; } } TagQueryToken nextToken = query.Peek(); if (nextToken != null) { NbtTag nextTag = Get(nextToken.Name); if (nextTag == null) { return; } nextTag.SetQuery <T>(query, val, false); Set(nextToken.Name, nextTag); return; } }
internal override T Query <T>(TagQuery query, bool bypassCheck) { TagQueryToken token = null; if (!bypassCheck) { token = query.Next(); if (token != null && !token.Name.Equals(Name)) { return(null); } } TagQueryToken nextToken = query.Peek(); if (nextToken != null) { NbtTag nextTag = Get(nextToken.Name); if (nextTag == null) { return(null); } return(nextTag.Query <T>(query)); } return((T)((NbtTag)this)); }
internal override T Query <T>(TagQuery query, bool bypassCheck) { TagQueryToken token = query.Next(); if (!bypassCheck) { if (token != null && !token.Name.Equals(Name)) { return(null); } } var nextToken = query.Peek(); if (nextToken != null) { // Make sure this token is an integer because NbtLists don't have // named tag items int tagIndex; if (!int.TryParse(nextToken.Name, out tagIndex)) { throw new NbtQueryException( string.Format("Attempt to query by name on a list tag that doesn't support names. ({0})", Name)); } var indexedTag = Get(tagIndex); if (indexedTag == null) { return(null); } if (query.TokensLeft() > 1) { // Pop the index token so the current token is the next // named token to continue the query query.Next(); // Bypass the name check because the tag won't have one return(indexedTag.Query <T>(query, true)); } return((T)indexedTag); } return((T)((NbtTag)this)); }
internal override void SetQuery <T>(TagQuery query, T val, bool bypassCheck) { if (bypassCheck) { return; } TagQueryToken token = query.Next(); if (token.Name.Equals(Name)) { if (query.Peek() != null) { throw new LibNbt.Exceptions.NbtQueryException(string.Format("Attempt through non list type tag: {0}", Name)); } Value = (string)Convert.ChangeType(val, typeof(string)); } }
/// <summary> /// Queries the tag to easily find a tag in a structure. /// </summary> /// <typeparam name="T">Type of the tag to return.</typeparam> /// <param name="query">Tokenized query</param> /// <param name="bypassCheck">Bypass the name check when querying non-named queries. /// NbtList elements are an example.</param> /// <returns>The tag that was queried for.</returns> internal virtual T Query <T>(TagQuery query, bool bypassCheck) where T : NbtTag { if (bypassCheck) { return((T)this); } TagQueryToken token = query.Next(); if (token.Name.Equals(Name)) { if (query.Peek() != null) { throw new NbtQueryException(string.Format("Attempt through non list type tag: {0}", Name)); } return((T)this); } return(null); }