CodeDomProvider Class
Updated: August 2008
Provides a base class for CodeDomProvider implementations. This class is abstract.
Assembly: System (in System.dll)
'Declaration <ComVisibleAttribute(True)> _ <PermissionSetAttribute(SecurityAction.LinkDemand, Name := "FullTrust")> _ <PermissionSetAttribute(SecurityAction.InheritanceDemand, Name := "FullTrust")> _ Public MustInherit Class CodeDomProvider _ Inherits Component 'Usage Dim instance As CodeDomProvider
A CodeDomProvider can be used to create and retrieve instances of code generators and code compilers. Code generators can be used to generate code in a particular language, and code compilers can be used to compile code into assemblies.
Note: |
|---|
In the .NET Framework version 2.0, the methods made available in the code generator and code compiler are available directly from the code provider. You do not need to call CreateGenerator or CreateCompiler to access the methods, and those methods are marked as obsolete. This applies to preexisting as well as new code provider implementations. |
A CodeDomProvider implementation typically provides code generation and/or code compilation interfaces for generating code and managing compilation for a single programming language. Several languages are supported by CodeDomProvider implementations that ship with the Windows Software Development Kit (SDK). These languages include C#, Visual Basic, C++, J#, and JScript. Developers or compiler vendors can implement the ICodeGenerator and ICodeCompiler interfaces and provide a CodeDomProvider that extends CodeDom support to other programming languages.
The <system.codedom> Element in the machine configuration file (Machine.config) provides a mechanism for developers and compiler vendors to add configuration settings for additional CodeDomProvider implementations.
The CodeDomProvider class provides static methods to discover and enumerate the CodeDomProvider implementations on a computer. The GetAllCompilerInfo method returns the settings for all CodeDomProvider implementations on a computer. The GetCompilerInfo method returns the settings for a specific CodeDomProvider implementation, based on the programming language name. The CreateProvider method returns an instance of a CodeDomProvider implementation for a specific language.
For more details on language provider settings in the configuration file, see Compiler and Language Provider Settings Schema.
Note: |
|---|
This class makes a link demand and an inheritance demand at the class level. A SecurityException is thrown if either the immediate caller or the derived class does not have full trust permission. For details about security demands, see Link Demands and Inheritance Demands. |
In the .NET Framework versions 1.0 and 1.1, code providers consist of implementations of CodeDomProvider, ICodeGenerator, ICodeParser, and ICodeCompiler. In the .NET Framework 2.0, the CreateGenerator, CreateParser, and CreateCompiler methods are obsolete, and the methods of ICodeGenerator and ICodeCompiler are directly available in the CodeDomProvider class. You should override those methods in your code provider implementation and not call the base methods.
The following code example determines the CodeDomProvider implementation for an input language and displays the configured settings for the language provider. This code example is part of a larger example provided for the CompilerInfo class.
Dim provider As CodeDomProvider ' Check for a provider corresponding to the input language. If CodeDomProvider.IsDefinedLanguage(language) Then provider = CodeDomProvider.CreateProvider(language) ' Display information about this language provider. Console.WriteLine("Language provider: {0}", _ provider.ToString()) Console.WriteLine() Console.WriteLine(" Default file extension: {0}", _ provider.FileExtension) Console.WriteLine() ' Get the compiler settings for this language. Dim langCompilerInfo As CompilerInfo = CodeDomProvider.GetCompilerInfo(language) Dim langCompilerConfig As CompilerParameters = langCompilerInfo.CreateDefaultCompilerParameters() Console.WriteLine(" Compiler options: {0}", _ langCompilerConfig.CompilerOptions) Console.WriteLine(" Compiler warning level: {0}", _ langCompilerConfig.WarningLevel) Else ' Tell the user that the language provider was not found. Console.WriteLine("There is no provider configured for input language ""{0}"".", _ language) End If
- SecurityAction.LinkDemand
for full trust for the immediate caller. This class cannot be used by partially trusted code.
- SecurityAction.InheritanceDemand
for full trust for inheritors. This class cannot be inherited by partially trusted code.
Windows 7, Windows Vista, Windows XP SP2, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP Starter Edition, Windows Server 2008 R2, Windows Server 2008, Windows Server 2003, Windows Server 2000 SP4, Windows Millennium Edition, Windows 98
The .NET Framework and .NET Compact Framework do not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.
Note: