Skip to content

Commit 7dafe6c

Browse files
mandel-macaqueGitHub Actions Autoformatter
andauthored
[RGen] Add new helper method in the text writter to append DynamicDependency attrs (#23407)
This attribute will be added in the protocol generation. --------- Co-authored-by: GitHub Actions Autoformatter <[email protected]>
1 parent 02d301f commit 7dafe6c

File tree

2 files changed

+31
-0
lines changed

2 files changed

+31
-0
lines changed

src/rgen/Microsoft.Macios.Generator/IO/TabbedStringBuilderExtensions.cs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,4 +130,19 @@ public static TabbedWriter<StringWriter> AppendPreserveAttribute (this TabbedWri
130130
self.WriteLine ($"[Preserve (Conditional = {conditional.ToString ().ToLower ()})]");
131131
return self;
132132
}
133+
134+
/// <summary>
135+
/// Appends a `[DynamicDependency]` attribute to the current writer.
136+
/// This attribute is used to indicate that a member has a dynamic dependency on another member.
137+
/// </summary>
138+
/// <param name="self">A tabbed string writer.</param>
139+
/// <param name="member">The member that is dynamically depended upon.</param>
140+
/// <returns>The current writer.</returns>
141+
public static TabbedWriter<StringWriter> AppendDynamicDependencyAttribute (this TabbedWriter<StringWriter> self,
142+
string member)
143+
{
144+
145+
self.WriteLine ($"[DynamicDependency ({member})]");
146+
return self;
147+
}
133148
}

tests/rgen/Microsoft.Macios.Generator.Tests/IO/TabbedStringBuilderTests.cs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -301,6 +301,22 @@ public void AppendPreserveAttribute (bool conditional, int tabCount, string expe
301301
Assert.Equal (expected, result);
302302
}
303303

304+
[Theory]
305+
[InlineData ("\"MyMember\"", 0, "")]
306+
[InlineData ("\"MyOtherMember\"", 1, "\t")]
307+
[InlineData ("nameof(MyProperty)", 5, "\t\t\t\t\t")]
308+
public void AppendDynamicDependencyAttributeTests (string member, int tabCount, string expectedTabs)
309+
{
310+
var expected = $"{expectedTabs}[DynamicDependency ({member})]\n";
311+
string result;
312+
using (var block = new TabbedStringBuilder (sb, tabCount)) {
313+
block.AppendDynamicDependencyAttribute (member);
314+
result = block.ToCode ();
315+
}
316+
317+
Assert.Equal (expected, result);
318+
}
319+
304320
[Theory]
305321
[InlineData (0, "")]
306322
[InlineData (1, "\t")]

0 commit comments

Comments
 (0)