CompilationUnit Class

Represents a compilation unit (source file) containing namespaces, types, and using directives.

Example

var unit = new CompilationUnit();
unit.Usings.Add(new UsingDirective("System"));
var ns = unit.AddNamespace("MyNamespace");
ns.AddType(new ClassDeclaration("MyClass"));
var code = unit.ToCsharpString();

Assert.StartsWith("using System;", code);
Assert.Contains("namespace MyNamespace", code);
Assert.Contains("class MyClass", code);
Inheritance
CodeObject CompilationUnit
Implements

Constructors

NameDescription
CompilationUnit()

CompilationUnit()

CompilationUnit.cs
public CompilationUnit()

No documentation is available.

Properties

NameDescription
CommentsAfter
CommentsBefore
NamespacesGets the collection of namespace declarations in this compilation unit.
NullableContextGets or sets the nullable reference types context for this compilation unit.
TypesGets the collection of top-level type declarations in this compilation unit.
UsingsGets the collection of using directives in this compilation unit.

CommentsAfter

CompilationUnit.cs
public CommentCollection CommentsAfter { get; }

Property value

CommentCollection

No documentation is available.

CommentsBefore

CompilationUnit.cs
public CommentCollection CommentsBefore { get; }

Property value

CommentCollection

No documentation is available.

Gets the collection of namespace declarations in this compilation unit.

public CodeObjectCollection<NamespaceDeclaration> Namespaces { get; }

NullableContext

CompilationUnit.cs

Gets or sets the nullable reference types context for this compilation unit.

public NullableContext NullableContext { get; set; }

Property value

NullableContext

Gets the collection of top-level type declarations in this compilation unit.

public CodeObjectCollection<TypeDeclaration> Types { get; }

Gets the collection of using directives in this compilation unit.

public CodeObjectCollection<UsingDirective> Usings { get; }