0

I am creating a property with SyntaxFactory (roslyn)

Dim [property] = SyntaxFactory .PropertyStatement("MyProperty").AddModifiers(SyntaxFactory .Token(SyntaxKind.FriendKeyword))

The result is

Friend Property MyProperty

To add the property type I probably need to use WithAsClause, but I can't find any usable example.

IvanH
  • 5,039
  • 14
  • 60
  • 81

1 Answers1

0

Finally I managed to find an example in Syntax Factory Tests:TestSpacingOnNullableDatetimeType and a solution is

Dim [property] = SyntaxFactory.PropertyStatement("MyProperty").AddModifiers(SyntaxFactory.Token(SyntaxKind.FriendKeyword)).
            WithAsClause(SyntaxFactory.SimpleAsClause(
            SyntaxFactory.PredefinedType(
               SyntaxFactory.Token(
                  SyntaxKind.StringKeyword)))) 

which has the desired result

Friend Property MyProperty As String

IvanH
  • 5,039
  • 14
  • 60
  • 81