CodeDomProvider.IsDefinedExtension(String) メソッド

定義

コンピューター上に、ファイル名拡張子の関連する CodeDomProvider 実装が構成されているかどうかを調べます。

public:
 static bool IsDefinedExtension(System::String ^ extension);
public static bool IsDefinedExtension (string extension);
[System.Runtime.InteropServices.ComVisible(false)]
public static bool IsDefinedExtension (string extension);
static member IsDefinedExtension : string -> bool
[<System.Runtime.InteropServices.ComVisible(false)>]
static member IsDefinedExtension : string -> bool
Public Shared Function IsDefinedExtension (extension As String) As Boolean

パラメーター

extension
String

ファイル名拡張子。

戻り値

指定したファイル名拡張子に対して、CodeDomProvider 実装が構成されている場合は true。それ以外の場合は false

属性

例外

extensionnull です。

呼び出し元に、必要なアクセス許可がありません。

次のコード例では、入力ファイル名拡張子の CodeDomProvider 実装を決定し、言語プロバイダーの構成済みの設定を表示します。 このコード例は、CompilerInfo クラスのために提供されている大規模な例の一部です。

if (  !fileExtension->StartsWith(  "." ) )
   fileExtension = String::Concat( ".", fileExtension );

// Get the language associated with the file extension.
CodeDomProvider^ provider = nullptr;
if ( CodeDomProvider::IsDefinedExtension( fileExtension ) )
{
   String^ language = CodeDomProvider::GetLanguageFromExtension( fileExtension );
   if ( language )
      Console::WriteLine( "The language \"{0}\" is associated with file extension \"{1}\"\n",
                           language, fileExtension );

   // Check for a corresponding language provider.
   if ( language && CodeDomProvider::IsDefinedLanguage( language ) )
   {
      provider = CodeDomProvider::CreateProvider( language );
      if ( provider )
      {
         // Display information about this language provider.
         Console::WriteLine( "Language provider:  {0}\n", provider->ToString() );
         
         // Get the compiler settings for this language.
         CompilerInfo^ langCompilerInfo = CodeDomProvider::GetCompilerInfo( language );
         if ( langCompilerInfo )
         {
            CompilerParameters^ langCompilerConfig = langCompilerInfo->CreateDefaultCompilerParameters();
            if ( langCompilerConfig )
            {
               Console::WriteLine( "  Compiler options:        {0}", langCompilerConfig->CompilerOptions );
               Console::WriteLine( "  Compiler warning level:  {0}", langCompilerConfig->WarningLevel.ToString() );
            }
         }
      }
   }
}

if ( provider == nullptr )  // Tell the user that the language provider was not found.
   Console::WriteLine( "There is no language provider associated with input file extension \"{0}\".", fileExtension );
if (fileExtension[0] != '.')
{
    fileExtension = "." + fileExtension;
}

// Get the language associated with the file extension.
if (CodeDomProvider.IsDefinedExtension(fileExtension))
{
    CodeDomProvider provider;
    String language = CodeDomProvider.GetLanguageFromExtension(fileExtension);

    Console.WriteLine("The language \"{0}\" is associated with file extension \"{1}\"",
        language, fileExtension);
    Console.WriteLine();

    // Next, check for a corresponding language provider.

    if (CodeDomProvider.IsDefinedLanguage(language))
    {
        provider = CodeDomProvider.CreateProvider(language);

        // Display information about this language provider.

        Console.WriteLine("Language provider:  {0}",
            provider.ToString());
        Console.WriteLine();

        // Get the compiler settings for this language.

        CompilerInfo langCompilerInfo = CodeDomProvider.GetCompilerInfo(language);
        CompilerParameters langCompilerConfig = 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 language provider associated with input file extension \"{0}\".",
        fileExtension);
}
If Not fileExtension.StartsWith(".") Then
   fileExtension = "." + fileExtension
End If

' Get the language associated with the file extension.
If CodeDomProvider.IsDefinedExtension(fileExtension) Then
   Dim provider As CodeDomProvider
   Dim language As String = CodeDomProvider.GetLanguageFromExtension(fileExtension)
   
   Console.WriteLine("The language ""{0}"" is associated with file extension ""{1}""", _
       language, fileExtension)
   Console.WriteLine()
   
   ' Check for a corresponding language provider.
   If CodeDomProvider.IsDefinedLanguage(language) Then
      provider = CodeDomProvider.CreateProvider(language)
      
      ' Display information about this language provider.
      Console.WriteLine("Language provider:  {0}", _
         provider.ToString())
      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)
   End If
Else
   ' Tell the user that the language provider was not found.
   Console.WriteLine("There is no language provider associated with input file extension ""{0}"".", fileExtension)
End If

注釈

コンピューター構成ファイル (Machine.config) の system.codedom> 要素には、コンピューター上の各実装の言語プロバイダーとコンパイラ構成設定が含まれています。<CodeDomProvider メソッドは IsDefinedExtension 、プロバイダー構成要素で指定されたファイル名拡張子を検索します。

ファイル名拡張子では大文字と小文字が区別されます。

適用対象

こちらもご覧ください