Skip to content

Commit 423d65b

Browse files
committed
change the tobicepexpression as an extension method
1 parent 12c9ffd commit 423d65b

File tree

5 files changed

+45
-35
lines changed

5 files changed

+45
-35
lines changed

sdk/provisioning/Azure.Provisioning/api/Azure.Provisioning.net8.0.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,10 @@ public void CopyTo(System.Collections.Generic.KeyValuePair<string, Azure.Provisi
3636
System.Collections.IEnumerator System.Collections.IEnumerable.GetEnumerator() { throw null; }
3737
public bool TryGetValue(string key, [System.Diagnostics.CodeAnalysis.MaybeNullWhenAttribute(false)] out Azure.Provisioning.BicepValue<T> value) { throw null; }
3838
}
39+
public static partial class BicepExpressionExtensions
40+
{
41+
public static Azure.Provisioning.Expressions.BicepExpression ToBicepExpression(this Azure.Provisioning.IBicepValue bicepValue) { throw null; }
42+
}
3943
public partial class BicepList<T> : Azure.Provisioning.BicepValue, System.Collections.Generic.ICollection<Azure.Provisioning.BicepValue<T>>, System.Collections.Generic.IEnumerable<Azure.Provisioning.BicepValue<T>>, System.Collections.Generic.IList<Azure.Provisioning.BicepValue<T>>, System.Collections.Generic.IReadOnlyCollection<Azure.Provisioning.BicepValue<T>>, System.Collections.Generic.IReadOnlyList<Azure.Provisioning.BicepValue<T>>, System.Collections.IEnumerable
4044
{
4145
public BicepList() { }

sdk/provisioning/Azure.Provisioning/api/Azure.Provisioning.netstandard2.0.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,10 @@ public void CopyTo(System.Collections.Generic.KeyValuePair<string, Azure.Provisi
3636
System.Collections.IEnumerator System.Collections.IEnumerable.GetEnumerator() { throw null; }
3737
public bool TryGetValue(string key, out Azure.Provisioning.BicepValue<T> value) { throw null; }
3838
}
39+
public static partial class BicepExpressionExtensions
40+
{
41+
public static Azure.Provisioning.Expressions.BicepExpression ToBicepExpression(this Azure.Provisioning.IBicepValue bicepValue) { throw null; }
42+
}
3943
public partial class BicepList<T> : Azure.Provisioning.BicepValue, System.Collections.Generic.ICollection<Azure.Provisioning.BicepValue<T>>, System.Collections.Generic.IEnumerable<Azure.Provisioning.BicepValue<T>>, System.Collections.Generic.IList<Azure.Provisioning.BicepValue<T>>, System.Collections.Generic.IReadOnlyCollection<Azure.Provisioning.BicepValue<T>>, System.Collections.Generic.IReadOnlyList<Azure.Provisioning.BicepValue<T>>, System.Collections.IEnumerable
4044
{
4145
public BicepList() { }
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
// Copyright (c) Microsoft Corporation. All rights reserved.
2+
// Licensed under the MIT License.
3+
4+
using System;
5+
using System.Collections.Generic;
6+
using System.Linq;
7+
using System.Text;
8+
using System.Threading.Tasks;
9+
using Azure.Provisioning.Expressions;
10+
11+
namespace Azure.Provisioning;
12+
13+
/// <summary>
14+
/// Provide extension methods for working with Bicep expressions.
15+
/// </summary>
16+
public static class BicepExpressionExtensions
17+
{
18+
public static BicepExpression ToBicepExpression(this IBicepValue bicepValue)
19+
{
20+
// if self is set, we could build an expression as a reference of this member
21+
if (bicepValue.Self is not null)
22+
{
23+
return bicepValue.Self.GetReference();
24+
}
25+
// if self is not set, but the value of this is an expression, we return that expression
26+
else if (bicepValue.Kind == BicepValueKind.Expression)
27+
{
28+
return bicepValue.Expression ?? BicepSyntax.Null();
29+
}
30+
// otherwise, we return whatever this compiles into
31+
else
32+
{
33+
return bicepValue.Compile();
34+
}
35+
}
36+
}

sdk/provisioning/Azure.Provisioning/src/BicepValue.cs

Lines changed: 1 addition & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
using System.ComponentModel;
66
using Azure.Provisioning.Expressions;
77
using Azure.Provisioning.Primitives;
8+
using Azure.Provisioning.Utilities;
89

910
namespace Azure.Provisioning;
1011

@@ -132,23 +133,4 @@ internal virtual void Assign(IBicepValue source)
132133
value._kind == BicepValueKind.Expression ?
133134
value._expression :
134135
value._self?.GetReference();
135-
136-
public BicepExpression ToBicepExpression()
137-
{
138-
// if self is set, we could build an expression as a reference of this member
139-
if (_self is not null)
140-
{
141-
return _self.GetReference();
142-
}
143-
// if self is not set, but the value of this is an expression, we return that expression
144-
else if (_kind == BicepValueKind.Expression)
145-
{
146-
return _expression ?? BicepSyntax.Null();
147-
}
148-
// otherwise, we return whatever this compiles into
149-
else
150-
{
151-
return Compile();
152-
}
153-
}
154136
}

sdk/provisioning/Azure.Provisioning/src/Primitives/ProvisionableConstruct.cs

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -363,20 +363,4 @@ protected T DefineModelProperty<T>(
363363
string? format = null)
364364
where T : ProvisionableConstruct, new()
365365
=> DefineModelProperty(propertyName, bicepPath, new T(), isOutput, isRequired, isSecure, format);
366-
367-
public BicepExpression ToBicepExpression()
368-
{
369-
if (_kind == BicepValueKind.Expression)
370-
{
371-
return _expression ?? BicepSyntax.Null();
372-
}
373-
else if (_self is not null)
374-
{
375-
return _self.GetReference();
376-
}
377-
else
378-
{
379-
return ((IBicepValue)this).Compile();
380-
}
381-
}
382366
}

0 commit comments

Comments
 (0)