// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt) // This code is distributed under MIT X11 license (for details please see \doc\license.txt) using System; using System.Collections.Generic; namespace ICSharpCode.NRefactory.VB.Ast { public abstract class Expression : AstNode { #region Null public new static readonly Expression Null = new NullExpression (); sealed class NullExpression : Expression { public override bool IsNull { get { return true; } } public override S AcceptVisitor (IAstVisitor visitor, T data) { return default (S); } protected internal override bool DoMatch(AstNode other, PatternMatching.Match match) { return other == null || other.IsNull; } } #endregion #region Builder methods /// /// Builds an member reference expression using this expression as target. /// public MemberAccessExpression Member(string memberName) { return new MemberAccessExpression { Target = this, MemberName = memberName }; } /// /// Builds an invocation expression using this expression as target. /// public InvocationExpression Invoke(string methodName, IEnumerable arguments) { return Invoke(methodName, null, arguments); } /// /// Builds an invocation expression using this expression as target. /// public InvocationExpression Invoke(string methodName, params Expression[] arguments) { return Invoke(methodName, null, arguments); } /// /// Builds an invocation expression using this expression as target. /// public InvocationExpression Invoke(string methodName, IEnumerable typeArguments, IEnumerable arguments) { InvocationExpression ie = new InvocationExpression(); MemberAccessExpression mre = new MemberAccessExpression(); mre.Target = this; mre.MemberName = methodName; mre.TypeArguments.AddRange(typeArguments); ie.Target = mre; ie.Arguments.AddRange(arguments); return ie; } /// /// Builds an invocation expression using this expression as target. /// public InvocationExpression Invoke(IEnumerable arguments) { InvocationExpression ie = new InvocationExpression(); ie.Target = this; ie.Arguments.AddRange(arguments); return ie; } /// /// Builds an invocation expression using this expression as target. /// public InvocationExpression Invoke(params Expression[] arguments) { InvocationExpression ie = new InvocationExpression(); ie.Target = this; ie.Arguments.AddRange(arguments); return ie; } public CastExpression CastTo(AstType type) { return new CastExpression { CastType = CastType.CType, Type = type, Expression = this }; } public CastExpression CastTo(Type type) { return new CastExpression { CastType = CastType.CType, Type = AstType.Create(type), Expression = this }; } #endregion } }