116 lines
5.0 KiB
C#
116 lines
5.0 KiB
C#
using Microsoft.CodeAnalysis.CSharp.Syntax.InternalSyntax;
|
|||
|
|
|
||
|
|
namespace Microsoft.CodeAnalysis.CSharp.Syntax;
|
||
|
|
|
||
|
|
public sealed class ConditionalExpressionSyntax : ExpressionSyntax
|
||
|
|
{
|
||
|
|
private ExpressionSyntax? condition;
|
||
|
|
|
||
|
|
private ExpressionSyntax? whenTrue;
|
||
|
|
|
||
|
|
private ExpressionSyntax? whenFalse;
|
||
|
|
|
||
|
|
public ExpressionSyntax Condition => ((SyntaxNode)this).GetRedAtZero<ExpressionSyntax>(ref condition);
|
||
|
|
|
||
|
|
public SyntaxToken QuestionToken => new SyntaxToken((SyntaxNode)(object)this, (GreenNode)(object)((Microsoft.CodeAnalysis.CSharp.Syntax.InternalSyntax.ConditionalExpressionSyntax)(object)((SyntaxNode)this).Green).questionToken, ((SyntaxNode)this).GetChildPosition(1), ((SyntaxNode)this).GetChildIndex(1));
|
||
|
|
|
||
|
|
public ExpressionSyntax WhenTrue => ((SyntaxNode)this).GetRed<ExpressionSyntax>(ref whenTrue, 2);
|
||
|
|
|
||
|
|
public SyntaxToken ColonToken => new SyntaxToken((SyntaxNode)(object)this, (GreenNode)(object)((Microsoft.CodeAnalysis.CSharp.Syntax.InternalSyntax.ConditionalExpressionSyntax)(object)((SyntaxNode)this).Green).colonToken, ((SyntaxNode)this).GetChildPosition(3), ((SyntaxNode)this).GetChildIndex(3));
|
||
|
|
|
||
|
|
public ExpressionSyntax WhenFalse => ((SyntaxNode)this).GetRed<ExpressionSyntax>(ref whenFalse, 4);
|
||
|
|
|
||
|
|
internal ConditionalExpressionSyntax(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<ExpressionSyntax>(ref condition),
|
||
|
|
2 => ((SyntaxNode)this).GetRed<ExpressionSyntax>(ref whenTrue, 2),
|
||
|
|
4 => ((SyntaxNode)this).GetRed<ExpressionSyntax>(ref whenFalse, 4),
|
||
|
|
_ => null,
|
||
|
|
});
|
||
|
|
}
|
||
|
|
|
||
|
|
internal override SyntaxNode? GetCachedSlot(int index)
|
||
|
|
{
|
||
|
|
return (SyntaxNode?)(index switch
|
||
|
|
{
|
||
|
|
0 => condition,
|
||
|
|
2 => whenTrue,
|
||
|
|
4 => whenFalse,
|
||
|
|
_ => null,
|
||
|
|
});
|
||
|
|
}
|
||
|
|
|
||
|
|
public override void Accept(CSharpSyntaxVisitor visitor)
|
||
|
|
{
|
||
|
|
visitor.VisitConditionalExpression(this);
|
||
|
|
}
|
||
|
|
|
||
|
|
public override TResult? Accept<TResult>(CSharpSyntaxVisitor<TResult> visitor)
|
||
|
|
{
|
||
|
|
return visitor.VisitConditionalExpression(this);
|
||
|
|
}
|
||
|
|
|
||
|
|
public ConditionalExpressionSyntax Update(ExpressionSyntax condition, SyntaxToken questionToken, ExpressionSyntax whenTrue, SyntaxToken colonToken, ExpressionSyntax whenFalse)
|
||
|
|
{
|
||
|
|
//IL_003a: Unknown result type (might be due to invalid IL or missing references)
|
||
|
|
//IL_003c: Unknown result type (might be due to invalid IL or missing references)
|
||
|
|
//IL_0009: Unknown result type (might be due to invalid IL or missing references)
|
||
|
|
//IL_000b: Unknown result type (might be due to invalid IL or missing references)
|
||
|
|
//IL_0020: Unknown result type (might be due to invalid IL or missing references)
|
||
|
|
//IL_0023: Unknown result type (might be due to invalid IL or missing references)
|
||
|
|
if (condition != Condition || questionToken != QuestionToken || whenTrue != WhenTrue || colonToken != ColonToken || whenFalse != WhenFalse)
|
||
|
|
{
|
||
|
|
ConditionalExpressionSyntax conditionalExpressionSyntax = SyntaxFactory.ConditionalExpression(condition, questionToken, whenTrue, colonToken, whenFalse);
|
||
|
|
SyntaxAnnotation[] annotations = ((SyntaxNode)this).GetAnnotations();
|
||
|
|
if (annotations == null || annotations.Length == 0)
|
||
|
|
{
|
||
|
|
return conditionalExpressionSyntax;
|
||
|
|
}
|
||
|
|
return conditionalExpressionSyntax.WithAnnotations(annotations);
|
||
|
|
}
|
||
|
|
return this;
|
||
|
|
}
|
||
|
|
|
||
|
|
public ConditionalExpressionSyntax WithCondition(ExpressionSyntax condition)
|
||
|
|
{
|
||
|
|
//IL_0003: Unknown result type (might be due to invalid IL or missing references)
|
||
|
|
//IL_000f: Unknown result type (might be due to invalid IL or missing references)
|
||
|
|
return Update(condition, QuestionToken, WhenTrue, ColonToken, WhenFalse);
|
||
|
|
}
|
||
|
|
|
||
|
|
public ConditionalExpressionSyntax WithQuestionToken(SyntaxToken questionToken)
|
||
|
|
{
|
||
|
|
//IL_0007: Unknown result type (might be due to invalid IL or missing references)
|
||
|
|
//IL_000f: Unknown result type (might be due to invalid IL or missing references)
|
||
|
|
return Update(Condition, questionToken, WhenTrue, ColonToken, WhenFalse);
|
||
|
|
}
|
||
|
|
|
||
|
|
public ConditionalExpressionSyntax WithWhenTrue(ExpressionSyntax whenTrue)
|
||
|
|
{
|
||
|
|
//IL_0008: Unknown result type (might be due to invalid IL or missing references)
|
||
|
|
//IL_000f: Unknown result type (might be due to invalid IL or missing references)
|
||
|
|
return Update(Condition, QuestionToken, whenTrue, ColonToken, WhenFalse);
|
||
|
|
}
|
||
|
|
|
||
|
|
public ConditionalExpressionSyntax WithColonToken(SyntaxToken colonToken)
|
||
|
|
{
|
||
|
|
//IL_0008: Unknown result type (might be due to invalid IL or missing references)
|
||
|
|
//IL_0013: Unknown result type (might be due to invalid IL or missing references)
|
||
|
|
return Update(Condition, QuestionToken, WhenTrue, colonToken, WhenFalse);
|
||
|
|
}
|
||
|
|
|
||
|
|
public ConditionalExpressionSyntax WithWhenFalse(ExpressionSyntax whenFalse)
|
||
|
|
{
|
||
|
|
//IL_0008: Unknown result type (might be due to invalid IL or missing references)
|
||
|
|
//IL_0014: Unknown result type (might be due to invalid IL or missing references)
|
||
|
|
return Update(Condition, QuestionToken, WhenTrue, ColonToken, whenFalse);
|
||
|
|
}
|
||
|
|
}
|