Click or drag to resize

CSharpCompilation Class



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.
Inheritance Hierarchy
SystemObject
  Microsoft.CodeAnalysisCompilation
    Microsoft.CodeAnalysis.CSharpCSharpCompilation

Namespace:  Microsoft.CodeAnalysis.CSharp
Assembly:  Microsoft.CodeAnalysis.CSharp (in Microsoft.CodeAnalysis.CSharp.dll) Version: 2.3.0-dev-56735-00. Commit Hash: <developer build>
Syntax
public sealed class CSharpCompilation : Compilation

The CSharpCompilation type exposes the following members.

Properties
  NameDescription
Public propertyAssembly
The IAssemblySymbol that represents the assembly being created.
(Inherited from Compilation.)
Public propertyAssemblyName
Simple assembly name, or null if not specified.
(Inherited from Compilation.)
Public propertyDirectiveReferences (Overrides CompilationDirectiveReferences.)
Public propertyDynamicType
The TypeSymbol for the type 'dynamic' in this Compilation.
(Inherited from Compilation.)
Public propertyExternalReferences
Metadata references passed to the compilation constructor.
(Inherited from Compilation.)
Public propertyGlobalNamespace
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.)
Public propertyIsCaseSensitive (Overrides CompilationIsCaseSensitive.)
Public propertyLanguage (Overrides CompilationLanguage.)
Public propertyLanguageVersion
The language version that was used to parse the syntax trees of this compilation.
Public propertyObjectType
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.)
Public propertyOptions
The options the compilation was created with.
Public propertyReferencedAssemblyNames (Overrides CompilationReferencedAssemblyNames.)
Public propertyReferences
All metadata references -- references passed to the compilation constructor as well as references specified via #r directives.
(Inherited from Compilation.)
Public propertyScriptClass
A symbol representing the implicit Script class. This is null if the class is not defined in the compilation.
(Inherited from Compilation.)
Public propertyScriptCompilationInfo
Public propertySourceModule
Gets the IModuleSymbol for the module being created by compiling all of the source code.
(Inherited from Compilation.)
Public propertySyntaxTrees
The syntax trees (parsed from source code) that this compilation was created with.
Top
Methods
  NameDescription
Public methodAddReferences(IEnumerableT) (Inherited from Compilation.)
Public methodAddReferences(IEnumerableT)
Public methodAddReferences(MetadataReference)
Creates a new compilation with additional metadata references.
Public methodAddSyntaxTrees(IEnumerableT) (Inherited from Compilation.)
Public methodAddSyntaxTrees(IEnumerableT)
Public methodAddSyntaxTrees(SyntaxTree)
Creates a new compilation with additional syntax trees.
Public methodClassifyConversion
Public methodClone
Create a duplicate of this compilation with different symbol instances.
Public methodContainsSymbolsWithName(FuncT, TResult, Boolean, String) (Inherited from Compilation.)
Public methodContainsSymbolsWithName(FuncT, TResult, Boolean, String)
Public methodContainsSyntaxTree
Returns true if this compilation contains the specified tree. False otherwise.
Public methodStatic memberCreate
Public methodCreateAnonymousTypeSymbol
Returns a new anonymous type symbol with the given member types member names. 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. Source locations can also be provided through memberLocations
(Inherited from Compilation.)
Public methodCreateArrayTypeSymbol
Returns a new ArrayTypeSymbol representing an array type tied to the base types of the COR Library in this Compilation.
(Inherited from Compilation.)
Public methodCreateDefaultWin32Resources
Create a stream filled with default win32 resources.
(Inherited from Compilation.)
Public methodCreateErrorNamespaceSymbol
Returns a new INamespaceSymbol representing an error (missing) namespace with the given name.
(Inherited from Compilation.)
Public methodCreateErrorTypeSymbol
Returns a new INamedTypeSymbol representing an error type with the given name and arity in the given optional container.
(Inherited from Compilation.)
Public methodCreatePointerTypeSymbol
Returns a new PointerTypeSymbol representing a pointer type tied to a type in this Compilation.
(Inherited from Compilation.)
Public methodStatic memberCreateScriptCompilation
Public methodCreateTupleTypeSymbol(INamedTypeSymbol, ImmutableArrayString, ImmutableArrayLocation)
Returns a new INamedTypeSymbol with the given underlying type and (optional) element names.
(Inherited from Compilation.)
Public methodCreateTupleTypeSymbol(ImmutableArrayITypeSymbol, ImmutableArrayString, ImmutableArrayLocation)
Returns a new INamedTypeSymbol with the given element types and (optional) element names.
(Inherited from Compilation.)
Public methodEmit(Stream, Stream, Stream, Stream, IEnumerableT, Void, ResourceDescription) (Inherited from Compilation.)
Public methodEmit(Stream, Stream, Stream, Stream, IEnumerableT, Void, ResourceDescription, EmitOptions) (Inherited from Compilation.)
Public methodEmit(Stream, Stream, Stream, Stream, IEnumerableT, Void, ResourceDescription, EmitOptions, IMethodSymbol, Stream) (Inherited from Compilation.)
Public methodEmitDifference(EmitBaseline, IEnumerableT, Void, SemanticEdit, Stream, Stream, Stream) (Inherited from Compilation.)
Public methodEmitDifference(EmitBaseline, IEnumerableT, Void, SemanticEdit, FuncT, TResult, Boolean, ISymbol, Boolean) (Inherited from Compilation.)
Public methodGetAssemblyOrModuleSymbol
Gets the IAssemblySymbol or IModuleSymbol for a metadata reference used to create this compilation.
(Inherited from Compilation.)
Public methodGetCompilationNamespace
Gets the corresponding compilation namespace for the specified module or assembly namespace.
(Inherited from Compilation.)
Public methodGetDeclarationDiagnostics(CancellationToken)
Gets the diagnostics produced during symbol declaration.
(Inherited from Compilation.)
Public methodGetDeclarationDiagnostics(CancellationToken)
Gets the diagnostics produced during symbol declaration headers. There are no diagnostics for accessor or method bodies, for example.
Public methodGetDiagnostics(CancellationToken)
Gets all the diagnostics for the compilation, including syntax, declaration, and binding. Does not include any diagnostics that might be produced during emit, see EmitResult.
(Inherited from Compilation.)
Public methodGetDiagnostics(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.
Public methodGetDirectiveReference
Returns a metadata reference that a given #r resolves to.
Public methodGetEntryPoint
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.)
Public methodGetMetadataReference
Gets the MetadataReference that corresponds to the assembly symbol.
Public methodGetMethodBodyDiagnostics(CancellationToken)
Gets the diagnostics produced during the analysis of method bodies and field initializers.
(Inherited from Compilation.)
Public methodGetMethodBodyDiagnostics(CancellationToken)
Gets the diagnostics produced during the analysis of method bodies and field initializers.
Public methodGetParseDiagnostics(CancellationToken)
Gets the diagnostics produced during the parsing stage.
(Inherited from Compilation.)
Public methodGetParseDiagnostics(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.
Public methodGetSemanticModel
Gets a new SyntaxTreeSemanticModel for the specified syntax tree.
Public methodGetSpecialType
Get the symbol for the predefined type from the Cor Library referenced by this compilation.
(Inherited from Compilation.)
Public methodGetSymbolsWithName(Void, ISymbol, FuncT, TResult) (Inherited from Compilation.)
Public methodGetSymbolsWithName(Void, ISymbol, FuncT, TResult)
Public methodGetTypeByMetadataName
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.)
Public methodGetUnreferencedAssemblyIdentities
Given a Diagnostic reporting unreferenced AssemblyIdentitys, returns the actual AssemblyIdentity instances that were not referenced.
(Inherited from Compilation.)
Public methodRemoveAllReferences
Creates a new compilation without any metadata references
Public methodRemoveAllSyntaxTrees
Creates a new compilation without any syntax trees. Preserves metadata info from this compilation for use with trees added later.
Public methodRemoveReferences(IEnumerableT) (Inherited from Compilation.)
Public methodRemoveReferences(IEnumerableT)
Public methodRemoveReferences(MetadataReference)
Creates a new compilation without the specified metadata references.
Public methodRemoveSyntaxTrees(IEnumerableT) (Inherited from Compilation.)
Public methodRemoveSyntaxTrees(IEnumerableT)
Public methodRemoveSyntaxTrees(SyntaxTree)
Creates a new compilation without the specified syntax trees. Preserves metadata info for use with trees added later.
Public methodReplaceReference
Creates a new compilation with an old metadata reference replaced with a new metadata reference.
Public methodReplaceSyntaxTree
Creates a new compilation without the old tree but with the new tree.
Public methodToMetadataReference(ImmutableArrayString, Boolean)
Creates a metadata reference for this compilation.
(Inherited from Compilation.)
Public methodToMetadataReference(ImmutableArrayString, Boolean)
Public methodWithAssemblyName
Creates a new compilation with the specified name.
Public methodWithOptions(CompilationOptions)
Creates a new compilation with the specified compilation options.
(Inherited from Compilation.)
Public methodWithOptions(CSharpCompilationOptions)
Creates a new compilation with the specified compilation options.
Public methodWithReferences(IEnumerableT) (Inherited from Compilation.)
Public methodWithReferences(IEnumerableT)
Public methodWithReferences(MetadataReference)
Creates a new compilation with the specified references.
Public methodWithScriptCompilationInfo(CSharpScriptCompilationInfo)
Returns a new compilation with the given compilation set as the previous submission.
Public methodWithScriptCompilationInfo(ScriptCompilationInfo) (Inherited from Compilation.)
Top
Extension Methods
  NameDescription
Public Extension MethodAliasImports
Gets the compilation AliasImports property.
(Defined by VisualBasicExtensions.)
Public Extension MethodClassifyConversion(ITypeSymbol, ITypeSymbol)Overloaded.
Determines what kind of conversion there is between the specified types.
(Defined by VisualBasicExtensions.)
Public Extension MethodClassifyConversion(ITypeSymbol, ITypeSymbol)Overloaded. (Defined by CSharpExtensions.)
Public Extension MethodEmit(String, String, String, String, IEnumerableT, Void)Overloaded. (Defined by CSharpFileSystemExtensions.)
Public Extension MethodEmit(String, String, String, String, IEnumerableT, Void)Overloaded. (Defined by FileSystemExtensions.)
Public Extension MethodGetSpecialType
Gets the special type symbol in current compilation.
(Defined by VisualBasicExtensions.)
Public Extension MethodMemberImports
Gets the compilation MemberImports property.
(Defined by VisualBasicExtensions.)
Public Extension MethodRootNamespace
Gets the compilation RootNamespace property.
(Defined by VisualBasicExtensions.)
Public Extension MethodWithAnalyzers(ImmutableArrayDiagnosticAnalyzer, CompilationWithAnalyzersOptions)Overloaded.
Returns a new compilation with attached diagnostic analyzers.
(Defined by DiagnosticAnalyzerExtensions.)
Public Extension MethodWithAnalyzers(ImmutableArrayDiagnosticAnalyzer, AnalyzerOptions, CancellationToken)Overloaded.
Returns a new compilation with attached diagnostic analyzers.
(Defined by DiagnosticAnalyzerExtensions.)
Top
See Also