Skip to content

Commit

Permalink
Merge branch 'feature/v3' into phase1-of-additionalproperties
Browse files Browse the repository at this point in the history
  • Loading branch information
ArcturusZhang committed Apr 15, 2024
2 parents 03fc0e3 + c8ab8cc commit 21ed249
Show file tree
Hide file tree
Showing 5 changed files with 90 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.

using AutoRest.CSharp.Common.Output.Expressions.ValueExpressions;
using AutoRest.CSharp.Generation.Writers;

namespace AutoRest.CSharp.Common.Output.Expressions.Statements
{
internal record CatchStatement(ValueExpression? Exception, MethodBodyStatement Body)
{
public void Write(CodeWriter writer)
{
writer.AppendRaw("catch");
if (Exception != null)
{
writer.AppendRaw(" (");
Exception.Write(writer);
writer.AppendRaw(")");
}
writer.LineRaw("{");
Body.Write(writer);
writer.LineRaw("}");
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
using System.Collections.Generic;
using AutoRest.CSharp.Common.Output.Expressions.KnownValueExpressions;
using AutoRest.CSharp.Common.Output.Expressions.ValueExpressions;
using AutoRest.CSharp.Common.Output.Models;
using AutoRest.CSharp.Generation.Writers;

namespace AutoRest.CSharp.Common.Output.Expressions.Statements
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,32 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.

using System.Collections.Generic;
using AutoRest.CSharp.Generation.Writers;

namespace AutoRest.CSharp.Common.Output.Expressions.Statements
{
internal record TryCatchFinallyStatement(MethodBodyStatement Try, MethodBodyStatement? Catch, MethodBodyStatement? Finally) : MethodBodyStatement;
internal record TryCatchFinallyStatement(MethodBodyStatement Try, IReadOnlyList<CatchStatement> Catches, MethodBodyStatement? Finally) : MethodBodyStatement
{
public override void Write(CodeWriter writer)
{
writer.LineRaw("try");
writer.LineRaw("{");
Try.Write(writer);
writer.LineRaw("}");

foreach (var catchStatement in Catches)
{
catchStatement.Write(writer);
}

if (Finally != null)
{
writer.LineRaw("finally");
writer.LineRaw("{");
Finally.Write(writer);
writer.LineRaw("}");
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.

using System.Collections;
using System.Collections.Generic;
using AutoRest.CSharp.Common.Output.Expressions.KnownValueExpressions;
using AutoRest.CSharp.Generation.Writers;

namespace AutoRest.CSharp.Common.Output.Expressions.Statements
{
internal record WhileStatement(BoolExpression Condition) : MethodBodyStatement, IEnumerable<MethodBodyStatement>
{
private readonly List<MethodBodyStatement> _body = new();
public IReadOnlyList<MethodBodyStatement> Body => _body;

public void Add(MethodBodyStatement statement) => _body.Add(statement);
public IEnumerator<MethodBodyStatement> GetEnumerator() => _body.GetEnumerator();
IEnumerator IEnumerable.GetEnumerator() => ((IEnumerable)_body).GetEnumerator();

public sealed override void Write(CodeWriter writer)
{
using (writer.AmbientScope())
{
writer.AppendRaw("while (");
Condition.Write(writer);
writer.LineRaw(")");

writer.LineRaw("{");
foreach (var bodyStatement in Body)
{
bodyStatement.Write(writer);
}
writer.LineRaw("}");
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ namespace AutoRest.CSharp.Common.Output.Expressions.ValueExpressions
// [TODO]: AddConfigureAwaitFalse is needed only in docs. Consider removing.
internal record InvokeInstanceMethodExpression(ValueExpression? InstanceReference, string MethodName, IReadOnlyList<ValueExpression> Arguments, IReadOnlyList<CSharpType>? TypeArguments, bool CallAsAsync, bool AddConfigureAwaitFalse = true) : ValueExpression
{
public InvokeInstanceMethodExpression(ValueExpression? instanceReference, string methodName, IReadOnlyList<ValueExpression> arguments, bool callAsAsync) : this(instanceReference, methodName, arguments, null, callAsAsync) { }

public InvokeInstanceMethodExpression(ValueExpression? instanceReference, MethodSignature signature, IReadOnlyList<ValueExpression> arguments, bool addConfigureAwaitFalse = true)
: this(instanceReference, signature.Name, arguments, signature.GenericArguments, signature.Modifiers.HasFlag(MethodSignatureModifiers.Async), addConfigureAwaitFalse) { }

Expand Down

0 comments on commit 21ed249

Please sign in to comment.