You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
Connected.Framework/Connected.Expressions/Translation/Resolvers/DeclaredAliasesResolver.cs

39 lines
751 B

2 years ago
using System.Linq.Expressions;
using Connected.Expressions.Expressions;
using Connected.Expressions.Visitors;
namespace Connected.Expressions.Translation.Resolvers;
internal sealed class DeclaredAliasesResolver : DatabaseVisitor
{
private DeclaredAliasesResolver()
{
Aliases = new();
}
private HashSet<Alias> Aliases { get; set; }
public static HashSet<Alias> Resolve(Expression source)
{
var resolver = new DeclaredAliasesResolver();
resolver.Visit(source);
return resolver.Aliases;
}
protected override Expression VisitSelect(SelectExpression select)
{
Aliases.Add(select.Alias);
return select;
}
protected override Expression VisitTable(TableExpression table)
{
Aliases.Add(table.Alias);
return table;
}
}