Udostępnij za pośrednictwem


VisualBasicCompilation Class

Definition

The Compilation object is an immutable representation of a single invocation of the compiler. Although immutable, a Compilation is also on-demand, in that a compilation can be created quickly, but will that compiler parts or all of the code in order to respond to method or properties. Also, a compilation can produce a new compilation with a small change from the current compilation. This is, in many cases, more efficient than creating a new compilation from scratch, as the new compilation can share information from the old compilation.

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

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)
CommonScriptGlobalsType (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
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 (Inherited from Compilation)
SourceModule

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

(Inherited from Compilation)
SyntaxTrees

Get a read-only list of the syntax trees that this compilation was created with.

Methods

AddReferences(IEnumerable<MetadataReference>)
AddReferences(MetadataReference[])
AddSyntaxTrees(IEnumerable<SyntaxTree>)
AddSyntaxTrees(SyntaxTree[])
AppendDefaultVersionResource(Stream) (Inherited from Compilation)
ClassifyCommonConversion(ITypeSymbol, ITypeSymbol)
ClassifyConversion(ITypeSymbol, ITypeSymbol)

Determine what kind of conversion, if any, there is between the types "source" and "destination".

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)
CommonCreateAnonymousTypeSymbol(ImmutableArray<ITypeSymbol>, ImmutableArray<String>, ImmutableArray<Location>, ImmutableArray<Boolean>) (Inherited from Compilation)
CommonCreateArrayTypeSymbol(ITypeSymbol, Int32, NullableAnnotation) (Inherited from Compilation)
CommonCreateArrayTypeSymbol(ITypeSymbol, Int32) (Inherited from Compilation)
CommonCreateBuiltinOperator(String, ITypeSymbol, ITypeSymbol, ITypeSymbol) (Inherited from Compilation)
CommonCreateBuiltinOperator(String, ITypeSymbol, ITypeSymbol) (Inherited from Compilation)
CommonCreateErrorNamespaceSymbol(INamespaceSymbol, String) (Inherited from Compilation)
CommonCreateErrorTypeSymbol(INamespaceOrTypeSymbol, String, Int32) (Inherited from Compilation)
CommonCreateFunctionPointerTypeSymbol(ITypeSymbol, RefKind, ImmutableArray<ITypeSymbol>, ImmutableArray<RefKind>, SignatureCallingConvention, ImmutableArray<INamedTypeSymbol>) (Inherited from Compilation)
CommonCreateFunctionPointerTypeSymbol(ITypeSymbol, RefKind, ImmutableArray<ITypeSymbol>, ImmutableArray<RefKind>) (Inherited from Compilation)
CommonCreateNativeIntegerTypeSymbol(Boolean) (Inherited from Compilation)
CommonCreatePointerTypeSymbol(ITypeSymbol) (Inherited from Compilation)
CommonCreateTupleTypeSymbol(ImmutableArray<ITypeSymbol>, ImmutableArray<String>, ImmutableArray<Location>, ImmutableArray<NullableAnnotation>) (Inherited from Compilation)
CommonCreateTupleTypeSymbol(ImmutableArray<ITypeSymbol>, ImmutableArray<String>, ImmutableArray<Location>) (Inherited from Compilation)
CommonCreateTupleTypeSymbol(INamedTypeSymbol, ImmutableArray<String>, ImmutableArray<Location>, ImmutableArray<NullableAnnotation>) (Inherited from Compilation)
CommonCreateTupleTypeSymbol(INamedTypeSymbol, ImmutableArray<String>, ImmutableArray<Location>) (Inherited from Compilation)
CommonGetAssemblyOrModuleSymbol(MetadataReference) (Inherited from Compilation)
CommonGetCompilationNamespace(INamespaceSymbol) (Inherited from Compilation)
CommonGetEntryPoint(CancellationToken) (Inherited from Compilation)
CommonGetSemanticModel(SyntaxTree, Boolean)

Gets a SemanticModel for the given syntaxTree. If Microsoft.CodeAnalysis.Compilation.SemanticModelProvider is non-null, it attempts to use Microsoft.CodeAnalysis.SemanticModelProvider.GetSemanticModel(Microsoft.CodeAnalysis.SyntaxTree,Microsoft.CodeAnalysis.Compilation,System.Boolean) to get a semantic model. Otherwise, it creates a new semantic model using Microsoft.CodeAnalysis.Compilation.CreateSemanticModel(Microsoft.CodeAnalysis.SyntaxTree,System.Boolean).

(Inherited from Compilation)
CommonGetSemanticModel(SyntaxTree, SemanticModelOptions)

Gets a SemanticModel for the given syntaxTree. If Microsoft.CodeAnalysis.Compilation.SemanticModelProvider is non-null, it attempts to use Microsoft.CodeAnalysis.SemanticModelProvider.GetSemanticModel(Microsoft.CodeAnalysis.SyntaxTree,Microsoft.CodeAnalysis.Compilation,Microsoft.CodeAnalysis.SemanticModelOptions) to get a semantic model. Otherwise, it creates a new semantic model using Microsoft.CodeAnalysis.Compilation.CreateSemanticModel(Microsoft.CodeAnalysis.SyntaxTree,Microsoft.CodeAnalysis.SemanticModelOptions).

(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 may be faster than ContainsSymbolsWithName(Func<String,Boolean>, SymbolFilter, CancellationToken) when predicate is just a simple string check. name is case insensitive.

ContainsSyntaxTree(SyntaxTree)

Is the passed in syntax tree in this compilation?

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

Create a new compilation from scratch.

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)
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)
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)
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)
CreateBuiltinOperator(String, ITypeSymbol, ITypeSymbol, ITypeSymbol)

Creates an IMethodSymbol whose MethodKind is BuiltinOperator for a binary operator. Built-in operators are commonly created for symbols like bool int.operator ==(int v1, int v2) which the language implicitly supports, even if such a symbol is not explicitly defined for that type in either source or metadata.

(Inherited from Compilation)
CreateBuiltinOperator(String, ITypeSymbol, ITypeSymbol)

Creates an IMethodSymbol whose MethodKind is BuiltinOperator for a unary operator. Built-in operators are commonly created for symbols like bool int.operator -(int value) which the language implicitly supports, even if such a symbol is not explicitly defined for that type in either source or metadata.

(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)
CreateFunctionPointerTypeSymbol(ITypeSymbol, RefKind, ImmutableArray<ITypeSymbol>, ImmutableArray<RefKind>, SignatureCallingConvention, ImmutableArray<INamedTypeSymbol>)

Returns a new IFunctionPointerTypeSymbol representing a function pointer type tied to types in this Compilation.

(Inherited from Compilation)
CreateFunctionPointerTypeSymbol(ITypeSymbol, RefKind, ImmutableArray<ITypeSymbol>, ImmutableArray<RefKind>)

Returns a new IFunctionPointerTypeSymbol representing a function pointer type tied to types in this Compilation.

(Inherited from Compilation)
CreateNativeIntegerTypeSymbol(Boolean)

Returns a new INamedTypeSymbol representing a native integer.

(Inherited from Compilation)
CreatePointerTypeSymbol(ITypeSymbol)

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

(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(ImmutableArray<ITypeSymbol>, ImmutableArray<String>, ImmutableArray<Location>)

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

(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)
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)
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, 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>, Func<ISymbol, Boolean>, Stream, Stream, Stream, ICollection<MethodDefinitionHandle>, CancellationToken)
Obsolete.

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)
Obsolete.

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)

Get declarations diagnostics for the entire compilation. This includes diagnostics from declarations, BUT NOT the bodies of methods or initializers. The set of declaration diagnostics is cached, so calling this method a second time should be fast.

GetDiagnostics(CancellationToken)

Get all diagnostics for the entire compilation. This includes diagnostics from parsing, declarations, and the bodies of methods. Getting all the diagnostics is potentially a length operations, as it requires parsing and compiling all the code. The set of diagnostics is not caches, so each call to this method will recompile all methods.

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.

(Inherited from Compilation)
GetMethodBodyDiagnostics(CancellationToken)

Get method body diagnostics for the entire compilation. This includes diagnostics only from the bodies of methods and initializers. These diagnostics are NOT cached, so calling this method a second time repeats significant work.

GetParseDiagnostics(CancellationToken)

Get parse diagnostics for the entire compilation. This includes diagnostics from parsing BUT NOT from declarations and the bodies of methods or initializers. The set of parse diagnostics is cached, so calling this method a second time should be fast.

GetSemanticModel(SyntaxTree, Boolean)

Get a fresh SemanticModel. Note that each invocation gets a fresh SemanticModel, each of which has a cache. Therefore, one effectively clears the cache by discarding the SemanticModel.

GetSemanticModel(SyntaxTree, SemanticModelOptions) (Inherited from Compilation)
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)
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. This lookup follows the following order:

  1. If the type is found in the compilation's assembly, that type is returned.
  2. Next, the core library (the library that defines System.Object and has no assembly references) is searched. If the type is found there, that type is returned.
  3. Finally, all remaining referenced non-extern assemblies are searched. If one and only one type matching the provided metadata name is found, that single type is returned. Accessibility is ignored for this check.
(Inherited from Compilation)
GetTypesByMetadataName(String)

Gets all types with the compilation's assembly and all referenced assemblies that have the given canonical CLR metadata name. Accessibility to the current assembly is ignored when searching for matching type names.

(Inherited from Compilation)
GetUnreferencedAssemblyIdentities(Diagnostic)

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

(Inherited from Compilation)
GetUsedAssemblyReferences(CancellationToken)
GetUsedAssemblyReferences(CancellationToken)

Unique metadata assembly references that are considered to be used by this compilation. For example, if a type declared in a referenced assembly is referenced in source code within this compilation, the reference is considered to be used. Etc. The returned set is a subset of references returned by References API. The result is undefined if the compilation contains errors.

The effect of imported namespaces on result of this API depends on whether reporting of unused imports is disabled for the compilation. The reporting of unused imports is disabled if DocumentationMode is set to None.

When unused imports reporting is disabled, all referenced assemblies containing any types that belong to imported namespaces are included in the result. I.e. considered used.

When unused imports reporting is enabled, imported namespaces do not have effect on the result of this API. Therefore, removing assembly references that aren't in the result, could potentially cause error "CS0246: The type or namespace name could not be found (are you missing a using directive or an assembly reference?)" on an unused namespace import. However, that import would be reported by compiler as unused for the compilation on which this API was invoked. In order to avoid the errors, it is recommended to remove unused assembly references and unused imports at the same time.

(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()
RemoveAllSyntaxTrees()
RemoveReferences(IEnumerable<MetadataReference>)
RemoveReferences(MetadataReference[])
RemoveSyntaxTrees(IEnumerable<SyntaxTree>)
RemoveSyntaxTrees(SyntaxTree[])
ReplaceReference(MetadataReference, MetadataReference)
ReplaceSyntaxTree(SyntaxTree, SyntaxTree)
SupportsRuntimeCapability(RuntimeCapability)

Determines whether the runtime this Compilation is targeting supports a particular capability.

(Inherited from Compilation)
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(VisualBasicCompilationOptions)
WithReferences(IEnumerable<MetadataReference>)

Creates a new compilation with the specified references.

WithReferences(MetadataReference[])
WithScriptCompilationInfo(ScriptCompilationInfo) (Inherited from Compilation)

Extension Methods

ClassifyConversion(Compilation, ITypeSymbol, ITypeSymbol)
WithAnalyzers(Compilation, ImmutableArray<DiagnosticAnalyzer>, AnalyzerOptions, CancellationToken)
Obsolete.

Returns a new compilation with attached diagnostic analyzers.

WithAnalyzers(Compilation, ImmutableArray<DiagnosticAnalyzer>, AnalyzerOptions)

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.

AliasImports(Compilation)

Gets the compilation AliasImports property.

ClassifyConversion(Compilation, ITypeSymbol, ITypeSymbol)

Determines what kind of conversion there is between the specified types.

GetSpecialType(Compilation, SpecialType)

Gets the special type symbol in current compilation.

MemberImports(Compilation)

Gets the compilation MemberImports property.

RootNamespace(Compilation)

Gets the compilation RootNamespace property.

Applies to