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 0c5b0df
Show file tree
Hide file tree
Showing 9 changed files with 90 additions and 18 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
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ void IJsonModel<ExtendsModelAdditionalProperties>.Write(Utf8JsonWriter writer, M
foreach (var item in AdditionalProperties)
{
writer.WritePropertyName(item.Key);
<<<<<<< HEAD
#if NET6_0_OR_GREATER
writer.WriteRawValue(item.Value);
#else
Expand All @@ -39,9 +38,6 @@ <<<<<<< HEAD
JsonSerializer.Serialize(writer, document.RootElement);
}
#endif
=======
writer.WriteObjectValue(item.Value, options);
>>>>>>> origin/feature/v3
}
writer.WriteEndObject();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ void IJsonModel<ExtendsModelArrayAdditionalProperties>.Write(Utf8JsonWriter writ
writer.WriteStartArray();
foreach (var item0 in item.Value)
{
<<<<<<< HEAD
if (item0 == null)
{
writer.WriteNullValue();
Expand All @@ -47,9 +46,6 @@ <<<<<<< HEAD
JsonSerializer.Serialize(writer, document.RootElement);
}
#endif
=======
writer.WriteObjectValue(item0, options);
>>>>>>> origin/feature/v3
}
writer.WriteEndArray();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ void IJsonModel<IsModelAdditionalProperties>.Write(Utf8JsonWriter writer, ModelR
foreach (var item in AdditionalProperties)
{
writer.WritePropertyName(item.Key);
<<<<<<< HEAD
#if NET6_0_OR_GREATER
writer.WriteRawValue(item.Value);
#else
Expand All @@ -39,9 +38,6 @@ <<<<<<< HEAD
JsonSerializer.Serialize(writer, document.RootElement);
}
#endif
=======
writer.WriteObjectValue(item.Value, options);
>>>>>>> origin/feature/v3
}
writer.WriteEndObject();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ void IJsonModel<IsModelArrayAdditionalProperties>.Write(Utf8JsonWriter writer, M
writer.WriteStartArray();
foreach (var item0 in item.Value)
{
<<<<<<< HEAD
if (item0 == null)
{
writer.WriteNullValue();
Expand All @@ -47,9 +46,6 @@ <<<<<<< HEAD
JsonSerializer.Serialize(writer, document.RootElement);
}
#endif
=======
writer.WriteObjectValue(item0, options);
>>>>>>> origin/feature/v3
}
writer.WriteEndArray();
}
Expand Down

0 comments on commit 0c5b0df

Please sign in to comment.