Skip to content

Commit 69d4ab8

Browse files
author
dahall
committed
Functional but unfinished check-in for VanaraAttributeGenerator
1 parent 97a1117 commit 69d4ab8

File tree

4 files changed

+205
-110
lines changed

4 files changed

+205
-110
lines changed

CodeGen/Generator/TypeDeclSyntaxExt.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
using Microsoft.CodeAnalysis.CSharp;
2+
using static Microsoft.CodeAnalysis.CSharp.SyntaxFactory;
23

34
namespace Vanara.Generators;
45

@@ -7,6 +8,11 @@ internal static class TypeDeclarationSyntaxExtensions
78
public static AttributeSyntax? GetAttr(this ParameterSyntax param, string name) =>
89
param.AttributeLists.SelectMany(al => al.Attributes).FirstOrDefault(a => a.NameEquals(name));
910

11+
public static VariableDeclarationSyntax CreateArrayVariableDeclaration(this ArrayTypeSyntax arrayType, string varName, string countVarName) =>
12+
VariableDeclaration(arrayType.WithRankSpecifiers(SingletonList(ArrayRankSpecifier())),
13+
SingletonSeparatedList(VariableDeclarator(Identifier(varName)).WithInitializer(EqualsValueClause(ParseExpression($"new {arrayType.ElementType}[{countVarName}]"))))
14+
);
15+
1016
public static bool NameEquals(this ArgumentSyntax arg, string name) =>
1117
(arg.NameColon?.Name.Identifier.Text == name) || (arg.Expression is IdentifierNameSyntax ins && ins.Identifier.Text == name);
1218

0 commit comments

Comments
 (0)