static QueryToken Append(this QueryToken baseToken, QueryToken suffix) { var steps = suffix.Follow(a => a.Parent).Reverse(); QueryToken token = baseToken; foreach (var step in steps) { QueryToken?newToken = null; if (step.Key == "Entity" && step is ColumnToken) { if (token.Type.CleanType() == step.Type.CleanType()) { continue; } else { newToken = token.SubTokenInternal("[" + TypeLogic.GetCleanName(baseToken.Type.CleanType()) + "]", SubTokensOptions.CanElement) !; } } newToken = token.SubTokenInternal(step.Key, SubTokensOptions.CanElement); token = newToken ?? throw new InvalidOperationException($"Token '{step}' not found in '{token.FullKey()}'"); } return(token); }
static QueryToken SubTokenBasic(QueryToken token, QueryDescription qd, string key) { if (token == null) { var column = qd.Columns.SingleOrDefaultEx(a=>a.Name == key); if (column == null) return null; return new ColumnToken(column, qd.QueryName); } else { return token.SubTokenInternal(key); } }