CompilerInfo.CreateProvider 方法
定義
重要
部分資訊涉及發行前產品,在發行之前可能會有大幅修改。 Microsoft 對此處提供的資訊,不做任何明確或隱含的瑕疵擔保。
傳回目前語言提供者設定的 CodeDomProvider 執行個體。
多載
CreateProvider() |
傳回目前語言提供者設定的 CodeDomProvider 執行個體。 |
CreateProvider(IDictionary<String,String>) |
傳回目前語言提供者設定和指定之選項的 CodeDomProvider 執行個體。 |
CreateProvider()
傳回目前語言提供者設定的 CodeDomProvider 執行個體。
public:
System::CodeDom::Compiler::CodeDomProvider ^ CreateProvider();
public System.CodeDom.Compiler.CodeDomProvider CreateProvider ();
member this.CreateProvider : unit -> System.CodeDom.Compiler.CodeDomProvider
Public Function CreateProvider () As CodeDomProvider
傳回
與語言提供者組態相關聯的 CodeDOM 提供者。
範例
下列程式代碼範例會列舉計算機上的語言提供者,並顯示每個語言提供者的組態和編譯程式設定。 此程式代碼範例是提供給 類別之較大範例的 CompilerInfo 一部分。
array<CompilerInfo^>^allCompilerInfo = CodeDomProvider::GetAllCompilerInfo();
for ( int i = 0; i < allCompilerInfo->Length; i++ )
{
String^ defaultLanguage;
String^ defaultExtension;
CompilerInfo^ info = allCompilerInfo[ i ];
CodeDomProvider^ provider = nullptr;
if ( info )
provider = info->CreateProvider();
if ( provider )
{
// Display information about this configured provider.
Console::WriteLine( "Language provider: {0}", provider->ToString() );
Console::WriteLine();
Console::WriteLine( " Supported file extension(s):" );
array<String^>^extensions = info->GetExtensions();
for ( int i = 0; i < extensions->Length; i++ )
Console::WriteLine( " {0}", extensions[ i ] );
defaultExtension = provider->FileExtension;
if ( !defaultExtension->StartsWith( "." ) )
defaultExtension = String::Concat( ".", defaultExtension );
Console::WriteLine( " Default file extension: {0}\n", defaultExtension );
Console::WriteLine( " Supported language(s):" );
array<String^>^languages = info->GetLanguages();
for ( int i = 0; i < languages->Length; i++ )
Console::WriteLine( " {0}", languages[ i ] );
defaultLanguage = CodeDomProvider::GetLanguageFromExtension( defaultExtension );
Console::WriteLine( " Default language: {0}", defaultLanguage );
Console::WriteLine();
// Get the compiler settings for this provider.
CompilerParameters^ langCompilerConfig = info->CreateDefaultCompilerParameters();
if ( langCompilerConfig )
{
Console::WriteLine( " Compiler options: {0}", langCompilerConfig->CompilerOptions );
Console::WriteLine( " Compiler warning level: {0}", langCompilerConfig->WarningLevel.ToString() );
}
}
}
CompilerInfo [] allCompilerInfo = CodeDomProvider.GetAllCompilerInfo();
foreach (CompilerInfo info in allCompilerInfo)
{
String defaultLanguage;
String defaultExtension;
CodeDomProvider provider = info.CreateProvider();
// Display information about this configured provider.
Console.WriteLine("Language provider: {0}",
provider.ToString());
Console.WriteLine();
Console.WriteLine(" Supported file extension(s):");
foreach(String extension in info.GetExtensions())
{
Console.WriteLine(" {0}", extension);
}
defaultExtension = provider.FileExtension;
if (defaultExtension[0] != '.')
{
defaultExtension = "." + defaultExtension;
}
Console.WriteLine(" Default file extension: {0}",
defaultExtension);
Console.WriteLine();
Console.WriteLine(" Supported language(s):");
foreach(String language in info.GetLanguages())
{
Console.WriteLine(" {0}", language);
}
defaultLanguage = CodeDomProvider.GetLanguageFromExtension(defaultExtension);
Console.WriteLine(" Default language: {0}",
defaultLanguage);
Console.WriteLine();
// Get the compiler settings for this provider.
CompilerParameters langCompilerConfig = info.CreateDefaultCompilerParameters();
Console.WriteLine(" Compiler options: {0}",
langCompilerConfig.CompilerOptions);
Console.WriteLine(" Compiler warning level: {0}",
langCompilerConfig.WarningLevel);
Console.WriteLine();
}
Dim allCompilerInfo As CompilerInfo() = CodeDomProvider.GetAllCompilerInfo()
Dim info As CompilerInfo
For Each info In allCompilerInfo
Dim defaultLanguage As String
Dim defaultExtension As String
Dim provider As CodeDomProvider = info.CreateProvider()
' Display information about this configured provider.
Console.WriteLine("Language provider: {0}", _
provider.ToString())
Console.WriteLine()
Console.WriteLine(" Supported file extension(s):")
Dim extension As String
For Each extension In info.GetExtensions()
Console.WriteLine(" {0}", extension)
Next extension
defaultExtension = provider.FileExtension
If Not defaultExtension.StartsWith(".") Then
defaultExtension = "." + defaultExtension
End If
Console.WriteLine(" Default file extension: {0}", _
defaultExtension)
Console.WriteLine()
Console.WriteLine(" Supported language(s):")
Dim language As String
For Each language In info.GetLanguages()
Console.WriteLine(" {0}", language)
Next language
defaultLanguage = CodeDomProvider.GetLanguageFromExtension(defaultExtension)
Console.WriteLine(" Default language: {0}", _
defaultLanguage)
Console.WriteLine()
' Get the compiler settings for this provider.
Dim langCompilerConfig As CompilerParameters = info.CreateDefaultCompilerParameters()
Console.WriteLine(" Compiler options: {0}", _
langCompilerConfig.CompilerOptions)
Console.WriteLine(" Compiler warning level: {0}", _
langCompilerConfig.WarningLevel)
Console.WriteLine()
Next info
備註
方法 CreateProvider 會 CodeDomProvider 傳回目前語言提供者設定的實例。
CreateProvider使用方法來取得 CodeDomProvider 或 CodeDomProvider.GetCompilerInfo 方法所傳回之實例的CodeDomProvider.GetAllCompilerInfo實CompilerInfo作。
另請參閱
適用於
CreateProvider(IDictionary<String,String>)
傳回目前語言提供者設定和指定之選項的 CodeDomProvider 執行個體。
public:
System::CodeDom::Compiler::CodeDomProvider ^ CreateProvider(System::Collections::Generic::IDictionary<System::String ^, System::String ^> ^ providerOptions);
public System.CodeDom.Compiler.CodeDomProvider CreateProvider (System.Collections.Generic.IDictionary<string,string> providerOptions);
member this.CreateProvider : System.Collections.Generic.IDictionary<string, string> -> System.CodeDom.Compiler.CodeDomProvider
Public Function CreateProvider (providerOptions As IDictionary(Of String, String)) As CodeDomProvider
參數
- providerOptions
- IDictionary<String,String>
來自組態檔的提供者選項集合。
傳回
與語言提供者組態和指定之選項相關聯的 CodeDOM 提供者。
例外狀況
providerOptions
為 null
。
提供者不支援選項。
備註
方法 CreateProvider(IDictionary<String,String>) 會 CodeDomProvider 傳回目前語言提供者設定和指定之提供者選項的實例。 如需支援之提供者選項的資訊,請參閱特定的CodeDOM提供者檔。
CreateProvider(IDictionary<String,String>)使用方法來取得 CodeDomProvider 或 CodeDomProvider.GetCompilerInfo 方法所傳回之實例的CodeDomProvider.GetAllCompilerInfo實CompilerInfo作。