Skip to content

Commit 1ef50e9

Browse files
committed
Allow outputting literal expressions as source blocks
1 parent e053621 commit 1ef50e9

File tree

2 files changed

+5
-6
lines changed

2 files changed

+5
-6
lines changed

src/CodeGeneration/DocGenerator/StringExtensions.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -218,7 +218,7 @@ public static string RemoveNumberOfLeadingTabsOrSpacesAfterNewline(this string i
218218

219219
public static string[] SplitOnNewLines(this string input, StringSplitOptions options) => input.Split(new[] { "\r\n", "\n" }, options);
220220

221-
public static bool TryGetJsonForAnonymousType(this string anonymousTypeString, out string json)
221+
public static bool TryGetJsonForExpressionSyntax(this string anonymousTypeString, out string json)
222222
{
223223
json = null;
224224

src/CodeGeneration/DocGenerator/SyntaxNodeExtensions.cs

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -71,12 +71,11 @@ public static bool TryGetJsonForSyntaxNode(this SyntaxNode node, out string json
7171
{
7272
json = null;
7373

74-
// find the first anonymous object or new object expression
75-
var creationExpressionSyntax = node.DescendantNodes()
76-
.FirstOrDefault(n => n is AnonymousObjectCreationExpressionSyntax || n is ObjectCreationExpressionSyntax);
74+
// find the first anonymous object, new object expression, or literal expression
75+
var syntax = node.DescendantNodes()
76+
.FirstOrDefault(n => n is AnonymousObjectCreationExpressionSyntax || n is ObjectCreationExpressionSyntax || n is LiteralExpressionSyntax);
7777

78-
return creationExpressionSyntax != null &&
79-
creationExpressionSyntax.ToFullString().TryGetJsonForAnonymousType(out json);
78+
return syntax != null && syntax.ToFullString().TryGetJsonForExpressionSyntax(out json);
8079
}
8180

8281
/// <summary>

0 commit comments

Comments
 (0)