75 lines
2.1 KiB
C#
75 lines
2.1 KiB
C#
using Microsoft.CodeAnalysis.CSharp.Syntax.InternalSyntax;
|
|
|
|
namespace Microsoft.CodeAnalysis.CSharp.Syntax;
|
|
|
|
public sealed class DeclarationExpressionSyntax : ExpressionSyntax
|
|
{
|
|
private TypeSyntax? type;
|
|
|
|
private VariableDesignationSyntax? designation;
|
|
|
|
public TypeSyntax Type => ((SyntaxNode)this).GetRedAtZero<TypeSyntax>(ref type);
|
|
|
|
public VariableDesignationSyntax Designation => ((SyntaxNode)this).GetRed<VariableDesignationSyntax>(ref designation, 1);
|
|
|
|
internal DeclarationExpressionSyntax(Microsoft.CodeAnalysis.CSharp.Syntax.InternalSyntax.CSharpSyntaxNode green, SyntaxNode? parent, int position)
|
|
: base(green, parent, position)
|
|
{
|
|
}
|
|
|
|
internal override SyntaxNode? GetNodeSlot(int index)
|
|
{
|
|
return (SyntaxNode?)(index switch
|
|
{
|
|
0 => ((SyntaxNode)this).GetRedAtZero<TypeSyntax>(ref type),
|
|
1 => ((SyntaxNode)this).GetRed<VariableDesignationSyntax>(ref designation, 1),
|
|
_ => null,
|
|
});
|
|
}
|
|
|
|
internal override SyntaxNode? GetCachedSlot(int index)
|
|
{
|
|
return (SyntaxNode?)(index switch
|
|
{
|
|
0 => type,
|
|
1 => designation,
|
|
_ => null,
|
|
});
|
|
}
|
|
|
|
public override void Accept(CSharpSyntaxVisitor visitor)
|
|
{
|
|
visitor.VisitDeclarationExpression(this);
|
|
}
|
|
|
|
public override TResult? Accept<TResult>(CSharpSyntaxVisitor<TResult> visitor)
|
|
{
|
|
return visitor.VisitDeclarationExpression(this);
|
|
}
|
|
|
|
public DeclarationExpressionSyntax Update(TypeSyntax type, VariableDesignationSyntax designation)
|
|
{
|
|
if (type != Type || designation != Designation)
|
|
{
|
|
DeclarationExpressionSyntax declarationExpressionSyntax = SyntaxFactory.DeclarationExpression(type, designation);
|
|
SyntaxAnnotation[] annotations = ((SyntaxNode)this).GetAnnotations();
|
|
if (annotations == null || annotations.Length == 0)
|
|
{
|
|
return declarationExpressionSyntax;
|
|
}
|
|
return declarationExpressionSyntax.WithAnnotations(annotations);
|
|
}
|
|
return this;
|
|
}
|
|
|
|
public DeclarationExpressionSyntax WithType(TypeSyntax type)
|
|
{
|
|
return Update(type, Designation);
|
|
}
|
|
|
|
public DeclarationExpressionSyntax WithDesignation(VariableDesignationSyntax designation)
|
|
{
|
|
return Update(Type, designation);
|
|
}
|
|
}
|