Skip to content

Commit

Permalink
Changes to support modifying methods via plugin (#4876)
Browse files Browse the repository at this point in the history
Contributes to #4798
  • Loading branch information
JoshLove-msft authored Oct 25, 2024
1 parent 057d0c6 commit 93a2c3f
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ public class FieldProvider
private VariableExpression? _variable;
private Lazy<ParameterProvider> _parameter;
public FormattableString? Description { get; }
public FieldModifiers Modifiers { get; }
public FieldModifiers Modifiers { get; set; }
public CSharpType Type { get; internal set; }
public string Name { get; }
public ValueExpression? InitializationValue { get; }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

namespace Microsoft.Generator.CSharp.Statements
{
internal class ExpressionStatement : MethodBodyStatement
public class ExpressionStatement : MethodBodyStatement
{
public ExpressionStatement(ValueExpression expression)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@

using System.Collections;
using System.Collections.Generic;
using System.Runtime.InteropServices;
using Microsoft.Generator.CSharp.Expressions;
using Microsoft.Generator.CSharp.Primitives;
using Microsoft.Generator.CSharp.Snippets;
Expand All @@ -17,7 +16,11 @@ public sealed class ForeachStatement : MethodBodyStatement, IEnumerable<MethodBo
public ValueExpression Enumerable { get; }
public bool IsAsync { get; }

public ForeachStatement(CSharpType? itemType, CodeWriterDeclaration item, ValueExpression enumerable, bool isAsync)
public VariableExpression ItemVariable { get; }

#pragma warning disable CS8618 // Non-nullable field must contain a non-null value when exiting constructor. Consider declaring as nullable.
private ForeachStatement(CSharpType? itemType, CodeWriterDeclaration item, ValueExpression enumerable, bool isAsync)
#pragma warning restore CS8618 // Non-nullable field must contain a non-null value when exiting constructor. Consider declaring as nullable.
{
ItemType = itemType;
Item = item;
Expand All @@ -26,31 +29,35 @@ public ForeachStatement(CSharpType? itemType, CodeWriterDeclaration item, ValueE
}

private readonly List<MethodBodyStatement> _body = new();
public IReadOnlyList<MethodBodyStatement> Body => _body;
public IList<MethodBodyStatement> Body => _body;

public ForeachStatement(CSharpType itemType, string itemName, ValueExpression enumerable, bool isAsync, out VariableExpression item)
: this(itemType, new CodeWriterDeclaration(itemName), enumerable, isAsync)
{
item = new VariableExpression(itemType, Item);
ItemVariable = item;
}

public ForeachStatement(string itemName, ScopedApi enumerable, out VariableExpression item)
: this(null, new CodeWriterDeclaration(itemName), enumerable, false)
{
item = new VariableExpression(enumerable.Type.Arguments[0], Item);
ItemVariable = item;
}

public ForeachStatement(string itemName, ScopedApi enumerable, bool isAsync, out VariableExpression item)
: this(null, new CodeWriterDeclaration(itemName), enumerable, isAsync)
{
item = new VariableExpression(enumerable.Type.Arguments[0], Item);
ItemVariable = item;
}

public ForeachStatement(string itemName, DictionaryExpression dictionary, out KeyValuePairExpression item)
: this(null, new CodeWriterDeclaration(itemName), dictionary, false)
{
var variable = new VariableExpression(dictionary.KeyValuePair, Item);
item = new(dictionary.KeyValuePair, variable);
ItemVariable = variable;
}

public static ForeachStatement Create<T>(string itemName, ScopedApi<IEnumerable<T>> enumerable, out ScopedApi<T> item)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ namespace Microsoft.Generator.CSharp.Statements
{
public sealed class IfStatement : MethodBodyStatement, IEnumerable<MethodBodyStatement>
{
public ValueExpression Condition { get; }
public ValueExpression Condition { get; set; }
public bool Inline { get; }
public bool AddBraces { get; }

Expand Down

0 comments on commit 93a2c3f

Please sign in to comment.