Skip to content

Instantly share code, notes, and snippets.

@TheLeftExit
Created September 21, 2025 15:08
Show Gist options
  • Select an option

  • Save TheLeftExit/175e004beb280c43af69f3d796ecffc4 to your computer and use it in GitHub Desktop.

Select an option

Save TheLeftExit/175e004beb280c43af69f3d796ecffc4 to your computer and use it in GitHub Desktop.
HelloWorldHelloWorld.cs
using Microsoft.CodeAnalysis;
using Microsoft.CodeAnalysis.CSharp;
using Microsoft.CodeAnalysis.CSharp.Syntax;
using static Microsoft.CodeAnalysis.CSharp.SyntaxFactory;
CompilationUnit()
.WithUsings(
SingletonList(
UsingDirective(
IdentifierName("System")
)
)
)
.WithMembers(
SingletonList<MemberDeclarationSyntax>(
ClassDeclaration("Program")
.WithModifiers(
TokenList(
Token(SyntaxKind.PublicKeyword),
Token(SyntaxKind.StaticKeyword)
)
)
.WithMembers(
SingletonList<MemberDeclarationSyntax>(
MethodDeclaration(
PredefinedType(
Token(SyntaxKind.VoidKeyword)
),
"Main"
)
.WithModifiers(
TokenList(
Token(SyntaxKind.PublicKeyword),
Token(SyntaxKind.StaticKeyword)
)
)
.WithBody(
Block(
ExpressionStatement(
InvocationExpression(
MemberAccessExpression(
SyntaxKind.SimpleMemberAccessExpression,
IdentifierName("Console"),
IdentifierName("WriteLine")
)
)
.WithArgumentList(
ArgumentList(
SingletonSeparatedList(
Argument(
LiteralExpression(
SyntaxKind.StringLiteralExpression,
Literal("Hello world!")
)
)
)
)
)
)
)
)
)
)
)
)
.NormalizeWhitespace()
.WriteTo(Console.Out);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment