Skip to content

Commit 1dfcac6

Browse files
Visit ScopedApi (#7368)
1 parent dd0561d commit 1dfcac6

File tree

2 files changed

+36
-2
lines changed

2 files changed

+36
-2
lines changed

packages/http-client-csharp/generator/Microsoft.TypeSpec.Generator/src/LibraryVisitor.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
using Microsoft.TypeSpec.Generator.Expressions;
66
using Microsoft.TypeSpec.Generator.Input;
77
using Microsoft.TypeSpec.Generator.Providers;
8+
using Microsoft.TypeSpec.Generator.Snippets;
89
using Microsoft.TypeSpec.Generator.Statements;
910

1011
namespace Microsoft.TypeSpec.Generator
@@ -202,6 +203,11 @@ internal virtual void Visit(OutputLibrary library)
202203
return statement;
203204
}
204205

206+
protected internal virtual ValueExpression? VisitScopedApiExpression(ScopedApi expression, MethodProvider method)
207+
{
208+
return expression;
209+
}
210+
205211
protected internal virtual MethodBodyStatement? VisitIfElseStatement(IfElseStatement statement, MethodProvider method)
206212
{
207213
return statement;

packages/http-client-csharp/generator/Microsoft.TypeSpec.Generator/src/Snippets/ScopedApi.cs

Lines changed: 30 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,15 @@
33

44
using Microsoft.TypeSpec.Generator.Expressions;
55
using Microsoft.TypeSpec.Generator.Primitives;
6+
using Microsoft.TypeSpec.Generator.Providers;
67
using Microsoft.TypeSpec.Generator.Statements;
78

89
namespace Microsoft.TypeSpec.Generator.Snippets
910
{
1011
public record ScopedApi : ValueExpression
1112
{
12-
public ValueExpression Original { get; }
13-
public CSharpType Type { get; }
13+
public ValueExpression Original { get; private set; }
14+
public CSharpType Type { get; private set; }
1415

1516
public ScopedApi(CSharpType type, ValueExpression original)
1617
: base(original)
@@ -28,5 +29,32 @@ internal override void Write(CodeWriter writer)
2829

2930
protected internal override bool IsEmptyExpression() => Original.IsEmptyExpression();
3031
public MethodBodyStatement Terminate() => _terminated ??= new ExpressionStatement(this);
32+
33+
internal override ValueExpression? Accept(LibraryVisitor visitor, MethodProvider method)
34+
{
35+
var updatedExpression = visitor.VisitScopedApiExpression(this, method);
36+
37+
if (updatedExpression is not ScopedApi scopedApi)
38+
{
39+
return updatedExpression?.Accept(visitor, method);
40+
}
41+
42+
scopedApi.Original = scopedApi.Original.Accept(visitor, method)!;
43+
44+
return scopedApi;
45+
}
46+
47+
public void Update(ValueExpression? original = null, CSharpType? type = null)
48+
{
49+
if (original != null)
50+
{
51+
Original = original;
52+
}
53+
54+
if (type != null)
55+
{
56+
Type = type;
57+
}
58+
}
3159
}
3260
}

0 commit comments

Comments
 (0)