CSharpCompilation Class

Definition

The compilation object is an immutable representation of a single invocation of the compiler. Although immutable, a compilation is also on-demand, and will realize and cache data as necessary. A compilation can produce a new compilation from existing compilation with the application of small deltas. In many cases, it is more efficient than creating a new compilation from scratch, as the new compilation can reuse information from the old compilation.

public ref class CSharpCompilation sealed : Microsoft::CodeAnalysis::Compilation
public sealed class CSharpCompilation : Microsoft.CodeAnalysis.Compilation
type CSharpCompilation = class
    inherit Compilation
Public NotInheritable Class CSharpCompilation
Inherits Compilation
Inheritance
CSharpCompilation

Fields

_features (Inherited from Compilation)

Properties

Assembly

The IAssemblySymbol that represents the assembly being created.

(Inherited from Compilation)
AssemblyName

Simple assembly name, or null if not specified.

(Inherited from Compilation)
CommonAssembly (Inherited from Compilation)
CommonDynamicType (Inherited from Compilation)
CommonGlobalNamespace (Inherited from Compilation)
CommonObjectType (Inherited from Compilation)
CommonOptions (Inherited from Compilation)
CommonScriptClass (Inherited from Compilation)
CommonSourceModule (Inherited from Compilation)
CommonSyntaxTrees (Inherited from Compilation)
DirectiveReferences
DynamicType

The TypeSymbol for the type 'dynamic' in this Compilation.

(Inherited from Compilation)
ExternalReferences

Metadata references passed to the compilation constructor.

(Inherited from Compilation)
GlobalNamespace

The root namespace that contains all namespaces and types defined in source code or in referenced metadata, merged into a single namespace hierarchy.

(Inherited from Compilation)
IsCaseSensitive
Language
LanguageVersion

The language version that was used to parse the syntax trees of this compilation.

ObjectType

The INamedTypeSymbol for the .NET System.Object type, which could have a TypeKind of Error if there was no COR Library in this Compilation.

(Inherited from Compilation)
Options

The options the compilation was created with.

ReferencedAssemblyNames
References

All metadata references -- references passed to the compilation constructor as well as references specified via #r directives.

(Inherited from Compilation)
ScriptClass

A symbol representing the implicit Script class. This is null if the class is not defined in the compilation.

(Inherited from Compilation)
ScriptCompilationInfo
SourceModule

Gets the IModuleSymbol for the module being created by compiling all of the source code.

(Inherited from Compilation)
SyntaxTrees

The syntax trees (parsed from source code) that this compilation was created with.

Methods

AddReferences(IEnumerable<MetadataReference>)

Creates a new compilation with additional metadata references.

AddReferences(MetadataReference[])

Creates a new compilation with additional metadata references.

AddSyntaxTrees(IEnumerable<SyntaxTree>)

Creates a new compilation with additional syntax trees.

AddSyntaxTrees(SyntaxTree[])

Creates a new compilation with additional syntax trees.

AppendDefaultVersionResource(Stream) (Inherited from Compilation)
ClassifyCommonConversion(ITypeSymbol, ITypeSymbol)

Classifies a conversion from source to destination according to this compilation's programming language.

ClassifyConversion(ITypeSymbol, ITypeSymbol)
Clone()

Create a duplicate of this compilation with different symbol instances.

CommonAddSyntaxTrees(IEnumerable<SyntaxTree>) (Inherited from Compilation)
CommonBindScriptClass()

Resolves a symbol that represents script container (Script class). Uses the full name of the container class stored in ScriptClassName to find the symbol.

(Inherited from Compilation)
CommonClone() (Inherited from Compilation)
CommonContainsSyntaxTree(SyntaxTree) (Inherited from Compilation)
CommonCreateAnonymousTypeSymbol(ImmutableArray<ITypeSymbol>, ImmutableArray<String>, ImmutableArray<Location>, ImmutableArray<Boolean>, ImmutableArray<NullableAnnotation>) (Inherited from Compilation)
CommonCreateArrayTypeSymbol(ITypeSymbol, Int32, NullableAnnotation) (Inherited from Compilation)
CommonCreateErrorNamespaceSymbol(INamespaceSymbol, String) (Inherited from Compilation)
CommonCreateErrorTypeSymbol(INamespaceOrTypeSymbol, String, Int32) (Inherited from Compilation)
CommonCreatePointerTypeSymbol(ITypeSymbol) (Inherited from Compilation)
CommonCreateTupleTypeSymbol(ImmutableArray<ITypeSymbol>, ImmutableArray<String>, ImmutableArray<Location>, ImmutableArray<NullableAnnotation>) (Inherited from Compilation)
CommonCreateTupleTypeSymbol(INamedTypeSymbol, ImmutableArray<String>, ImmutableArray<Location>, ImmutableArray<NullableAnnotation>) (Inherited from Compilation)
CommonGetAssemblyOrModuleSymbol(MetadataReference) (Inherited from Compilation)
CommonGetCompilationNamespace(INamespaceSymbol) (Inherited from Compilation)
CommonGetEntryPoint(CancellationToken) (Inherited from Compilation)
CommonGetSemanticModel(SyntaxTree, Boolean) (Inherited from Compilation)
CommonGetSpecialType(SpecialType) (Inherited from Compilation)
CommonGetTypeByMetadataName(String) (Inherited from Compilation)
CommonRemoveAllSyntaxTrees() (Inherited from Compilation)
CommonRemoveSyntaxTrees(IEnumerable<SyntaxTree>) (Inherited from Compilation)
CommonReplaceSyntaxTree(SyntaxTree, SyntaxTree) (Inherited from Compilation)
CommonWithAssemblyName(String) (Inherited from Compilation)
CommonWithOptions(CompilationOptions) (Inherited from Compilation)
CommonWithReferences(IEnumerable<MetadataReference>)

Creates a new compilation with the specified references.

(Inherited from Compilation)
CommonWithScriptCompilationInfo(ScriptCompilationInfo) (Inherited from Compilation)
ContainsSymbolsWithName(Func<String,Boolean>, SymbolFilter, CancellationToken)

Return true if there is a source declaration symbol name that meets given predicate.

ContainsSymbolsWithName(String, SymbolFilter, CancellationToken)

Return true if there is a source declaration symbol name that matches the provided name. This will be faster than ContainsSymbolsWithName(Func<String,Boolean>, SymbolFilter, CancellationToken) when predicate is just a simple string check.

ContainsSyntaxTree(SyntaxTree)

Returns true if this compilation contains the specified tree. False otherwise.

Create(String, IEnumerable<SyntaxTree>, IEnumerable<MetadataReference>, CSharpCompilationOptions)

Creates a new compilation from scratch. Methods such as AddSyntaxTrees or AddReferences on the returned object will allow to continue building up the Compilation incrementally.

CreateAnonymousTypeSymbol(ImmutableArray<ITypeSymbol>, ImmutableArray<String>, ImmutableArray<Boolean>, ImmutableArray<Location>)

Returns a new anonymous type symbol with the given member types, names, and source locations. Anonymous type members will be readonly by default. Writable properties are supported in VB and can be created by passing in false in the appropriate locations in memberIsReadOnly.

(Inherited from Compilation)
CreateAnonymousTypeSymbol(ImmutableArray<ITypeSymbol>, ImmutableArray<String>, ImmutableArray<Boolean>, ImmutableArray<Location>, ImmutableArray<NullableAnnotation>)

Returns a new anonymous type symbol with the given member types, names, source locations, and nullable annotations. Anonymous type members will be readonly by default. Writable properties are supported in VB and can be created by passing in false in the appropriate locations in memberIsReadOnly.

(Inherited from Compilation)
CreateArrayTypeSymbol(ITypeSymbol, Int32)

Returns a new ArrayTypeSymbol representing an array type tied to the base types of the COR Library in this Compilation.

(Inherited from Compilation)
CreateArrayTypeSymbol(ITypeSymbol, Int32, NullableAnnotation)

Returns a new ArrayTypeSymbol representing an array type tied to the base types of the COR Library in this Compilation.

(Inherited from Compilation)
CreateDefaultWin32Resources(Boolean, Boolean, Stream, Stream)

Create a stream filled with default win32 resources.

(Inherited from Compilation)
CreateErrorNamespaceSymbol(INamespaceSymbol, String)

Returns a new INamespaceSymbol representing an error (missing) namespace with the given name.

(Inherited from Compilation)
CreateErrorTypeSymbol(INamespaceOrTypeSymbol, String, Int32)

Returns a new INamedTypeSymbol representing an error type with the given name and arity in the given optional container.

(Inherited from Compilation)
CreatePointerTypeSymbol(ITypeSymbol)

Returns a new PointerTypeSymbol representing a pointer type tied to a type in this Compilation.

(Inherited from Compilation)
CreateScriptCompilation(String, SyntaxTree, IEnumerable<MetadataReference>, CSharpCompilationOptions, CSharpCompilation, Type, Type)

Creates a new compilation that can be used in scripting.

CreateTupleTypeSymbol(ImmutableArray<ITypeSymbol>, ImmutableArray<String>, ImmutableArray<Location>)

Returns a new INamedTypeSymbol with the given element types, names, and locations.

(Inherited from Compilation)
CreateTupleTypeSymbol(ImmutableArray<ITypeSymbol>, ImmutableArray<String>, ImmutableArray<Location>, ImmutableArray<NullableAnnotation>)

Returns a new INamedTypeSymbol with the given element types and (optional) element names, locations, and nullable annotations.

(Inherited from Compilation)
CreateTupleTypeSymbol(INamedTypeSymbol, ImmutableArray<String>, ImmutableArray<Location>)

Returns a new INamedTypeSymbol with the given underlying type and element names and locations. The underlying type needs to be tuple-compatible.

(Inherited from Compilation)
CreateTupleTypeSymbol(INamedTypeSymbol, ImmutableArray<String>, ImmutableArray<Location>, ImmutableArray<NullableAnnotation>)

Returns a new INamedTypeSymbol with the given underlying type and (optional) element names, locations, and nullable annotations. The underlying type needs to be tuple-compatible.

(Inherited from Compilation)
Emit(Stream, Stream, Stream, Stream, IEnumerable<ResourceDescription>, EmitOptions, CancellationToken) (Inherited from Compilation)
Emit(Stream, Stream, Stream, Stream, IEnumerable<ResourceDescription>, EmitOptions, IMethodSymbol, CancellationToken) (Inherited from Compilation)
Emit(Stream, Stream, Stream, Stream, IEnumerable<ResourceDescription>, EmitOptions, IMethodSymbol, Stream, IEnumerable<EmbeddedText>, CancellationToken) (Inherited from Compilation)
Emit(Stream, Stream, Stream, Stream, IEnumerable<ResourceDescription>, EmitOptions, IMethodSymbol, Stream, IEnumerable<EmbeddedText>, Stream, CancellationToken)

Emit the IL for the compiled source code into the specified stream.

(Inherited from Compilation)
EmitDifference(EmitBaseline, IEnumerable<SemanticEdit>, Func<ISymbol,Boolean>, Stream, Stream, Stream, ICollection<MethodDefinitionHandle>, CancellationToken)

Emit the differences between the compilation and the previous generation for Edit and Continue. The differences are expressed as added and changed symbols, and are emitted as metadata, IL, and PDB deltas. A representation of the current compilation is returned as an EmitBaseline for use in a subsequent Edit and Continue.

(Inherited from Compilation)
EmitDifference(EmitBaseline, IEnumerable<SemanticEdit>, Stream, Stream, Stream, ICollection<MethodDefinitionHandle>, CancellationToken)

Emit the differences between the compilation and the previous generation for Edit and Continue. The differences are expressed as added and changed symbols, and are emitted as metadata, IL, and PDB deltas. A representation of the current compilation is returned as an EmitBaseline for use in a subsequent Edit and Continue.

(Inherited from Compilation)
GetAssemblyOrModuleSymbol(MetadataReference)

Gets the IAssemblySymbol or IModuleSymbol for a metadata reference used to create this compilation.

(Inherited from Compilation)
GetCompilationNamespace(INamespaceSymbol)

Gets the corresponding compilation namespace for the specified module or assembly namespace.

(Inherited from Compilation)
GetDeclarationDiagnostics(CancellationToken)

Gets the diagnostics produced during symbol declaration headers. There are no diagnostics for accessor or method bodies, for example.

GetDiagnostics(CancellationToken)

Gets the all the diagnostics for the compilation, including syntax, declaration, and binding. Does not include any diagnostics that might be produced during emit.

GetDirectiveReference(ReferenceDirectiveTriviaSyntax)

Returns a metadata reference that a given #r resolves to.

GetEntryPoint(CancellationToken)

Returns the Main method that will serves as the entry point of the assembly, if it is executable (and not a script).

(Inherited from Compilation)
GetMetadataReference(IAssemblySymbol)

Gets the MetadataReference that corresponds to the assembly symbol.

GetMethodBodyDiagnostics(CancellationToken)

Gets the diagnostics produced during the analysis of method bodies and field initializers.

GetParseDiagnostics(CancellationToken)

Gets the diagnostics produced during the parsing stage of a compilation. There are no diagnostics for declarations or accessor or method bodies, for example.

GetSemanticModel(SyntaxTree, Boolean)

Gets a new SyntaxTreeSemanticModel for the specified syntax tree.

GetSpecialType(SpecialType)

Get the symbol for the predefined type from the Cor Library referenced by this compilation.

(Inherited from Compilation)
GetSymbolsWithName(Func<String,Boolean>, SymbolFilter, CancellationToken)

Return source declaration symbols whose name meets given predicate.

GetSymbolsWithName(String, SymbolFilter, CancellationToken)

Return source declaration symbols whose name matches the provided name. This will be faster than GetSymbolsWithName(Func<String,Boolean>, SymbolFilter, CancellationToken) when predicate is just a simple string check. name is case sensitive.

GetTypeByMetadataName(String)

Gets the type within the compilation's assembly and all referenced assemblies (other than those that can only be referenced via an extern alias) using its canonical CLR metadata name.

(Inherited from Compilation)
GetUnreferencedAssemblyIdentities(Diagnostic)

Given a Diagnostic reporting unreferenced AssemblyIdentitys, returns the actual AssemblyIdentity instances that were not referenced.

(Inherited from Compilation)
HasImplicitConversion(ITypeSymbol, ITypeSymbol)

Returns true if there is an implicit (C#) or widening (VB) conversion from fromType to toType. Returns false if either fromType or toType is null, or if no such conversion exists.

(Inherited from Compilation)
IsSymbolAccessibleWithin(ISymbol, ISymbol, ITypeSymbol)

Checks if symbol is accessible from within within. An optional qualifier of type throughType is used to resolve protected access for instance members. All symbols are required to be from this compilation or some assembly referenced (References) by this compilation. within is required to be an INamedTypeSymbol or IAssemblySymbol.

(Inherited from Compilation)
RemoveAllReferences()

Creates a new compilation without any metadata references

RemoveAllSyntaxTrees()

Creates a new compilation without any syntax trees. Preserves metadata info from this compilation for use with trees added later.

RemoveReferences(IEnumerable<MetadataReference>)

Creates a new compilation without the specified metadata references.

RemoveReferences(MetadataReference[])

Creates a new compilation without the specified metadata references.

RemoveSyntaxTrees(IEnumerable<SyntaxTree>)

Creates a new compilation without the specified syntax trees. Preserves metadata info for use with trees added later.

RemoveSyntaxTrees(SyntaxTree[])

Creates a new compilation without the specified syntax trees. Preserves metadata info for use with trees added later.

ReplaceReference(MetadataReference, MetadataReference)

Creates a new compilation with an old metadata reference replaced with a new metadata reference.

ReplaceSyntaxTree(SyntaxTree, SyntaxTree)

Creates a new compilation without the old tree but with the new tree.

ToMetadataReference(ImmutableArray<String>, Boolean)
WithAssemblyName(String)

Creates a new compilation with the specified name.

WithOptions(CompilationOptions)

Creates a new compilation with the specified compilation options.

(Inherited from Compilation)
WithOptions(CSharpCompilationOptions)

Creates a new compilation with the specified compilation options.

WithReferences(IEnumerable<MetadataReference>)

Creates a new compilation with the specified references.

WithReferences(MetadataReference[])

Creates a new compilation with the specified references.

WithScriptCompilationInfo(CSharpScriptCompilationInfo)

Returns a new compilation with the given compilation set as the previous submission.

WithScriptCompilationInfo(ScriptCompilationInfo) (Inherited from Compilation)

Extension Methods

ClassifyConversion(Compilation, ITypeSymbol, ITypeSymbol)
Emit(CSharpCompilation, String, String, String, String, IEnumerable<ResourceDescription>, CancellationToken)

Emit the IL for the compilation into the specified stream.

WithAnalyzers(Compilation, ImmutableArray<DiagnosticAnalyzer>, AnalyzerOptions, CancellationToken)

Returns a new compilation with attached diagnostic analyzers.

WithAnalyzers(Compilation, ImmutableArray<DiagnosticAnalyzer>, CompilationWithAnalyzersOptions)

Returns a new compilation with attached diagnostic analyzers.

Emit(Compilation, String, String, String, String, IEnumerable<ResourceDescription>, CancellationToken)

Emit the IL for the compilation into the specified stream.

Applies to