CompilationUnit Class
Represents a compilation unit (source file) containing namespaces, types, and using directives.
public class CompilationUnit : CodeObject, ICommentable, INamespaceDeclarationContainer, INullableContext, ITypeDeclarationContainer, IUsingDirectiveContainerExample
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
CodeObjectCompilationUnit- Implements
Constructors
| Name | Description |
|---|---|
| CompilationUnit() |
CompilationUnit()
CompilationUnit.cspublic CompilationUnit()No documentation is available.
Properties
| Name | Description |
|---|---|
| CommentsAfter | |
| CommentsBefore | |
| Namespaces | Gets the collection of namespace declarations in this compilation unit. |
| NullableContext | Gets or sets the nullable reference types context for this compilation unit. |
| Types | Gets the collection of top-level type declarations in this compilation unit. |
| Usings | Gets the collection of using directives in this compilation unit. |
CommentsAfter
CompilationUnit.csCommentsBefore
CompilationUnit.csNamespaces
CompilationUnit.csGets the collection of namespace declarations in this compilation unit.
public CodeObjectCollection<NamespaceDeclaration> Namespaces { get; }Property value
NullableContext
CompilationUnit.csGets or sets the nullable reference types context for this compilation unit.
public NullableContext NullableContext { get; set; }Property value
Types
CompilationUnit.csGets the collection of top-level type declarations in this compilation unit.
public CodeObjectCollection<TypeDeclaration> Types { get; }Property value
Usings
CompilationUnit.csGets the collection of using directives in this compilation unit.
public CodeObjectCollection<UsingDirective> Usings { get; }