次の方法で共有


AssemblyName.GetAssemblyName メソッド

指定したファイルの AssemblyName を取得します。

Public Shared Function GetAssemblyName( _
   ByVal assemblyFile As String _) As AssemblyName
[C#]
public static AssemblyName GetAssemblyName(stringassemblyFile);
[C++]
public: static AssemblyName* GetAssemblyName(String* assemblyFile);
[JScript]
public static function GetAssemblyName(
   assemblyFile : String) : AssemblyName;

パラメータ

  • assemblyFile
    AssemblyName を取得する対象となるアセンブリ ファイル。

戻り値

指定したファイルを表す AssemblyName オブジェクト。

例外

例外の種類 条件
ArgumentNullException assemblyFile が null 参照 (Visual Basic では Nothing) です。
ArgumentException assemblyFile が空です。
FileNotFoundException assemblyFile が見つかりません。
SecurityException 呼び出し元に、パス探索のアクセス許可がありません。
BadImageFormatException assemblyFile が有効なアセンブリではありません。

解説

このメソッドは、ファイルにアセンブリ マニフェストが含まれている場合にだけ機能します。このメソッドを使用すると、ファイルは開閉されますが、アセンブリはこのドメインに追加されません。

使用例

 
Imports System
Imports System.Reflection
Imports System.Text.RegularExpressions
Imports Microsoft.VisualBasic

Public Class AssemblyName_GetAssemblyName
   
   Public Shared Sub Main()
      

      ' Get the type of 'System.Object'.
      Dim myType As Type = GetType(System.Object)
      
      ' Get the path of 'System.dll'.
      Dim system As String = Regex.Replace(myType.Assembly.CodeBase, "mscorlib.dll", "System.dll")
      system = Regex.Replace(system, "file:///", "")
      
      ' Get the assembly information and display to the console.
      Dim myAssemblyName As AssemblyName = AssemblyName.GetAssemblyName(system)
      Console.WriteLine(ControlChars.Cr + "Displaying the assembly information of 'System.dll'" + ControlChars.Cr)
      Console.WriteLine(myAssemblyName.ToString())
   End Sub 'Main 
End Class 'AssemblyName_GetAssemblyName 

[C#] 

using System;
using System.Reflection;
using System.Text.RegularExpressions;

public class AssemblyName_GetAssemblyName
{
   public static void Main()
   {


      // Get the type of 'System.Object'.
      Type myType = typeof(System.Object);
      
      // Get the path of 'System.dll'.
      string system = Regex.Replace(myType.Assembly.CodeBase, "mscorlib.dll", "System.dll");
      system = Regex.Replace(system, "file:///", "");

      // Get the assembly information and display to the console.
      AssemblyName myAssemblyName = AssemblyName.GetAssemblyName(system);
      Console.WriteLine("\nDisplaying the assembly information of 'System.dll'\n");
      Console.WriteLine(myAssemblyName.ToString());
   }
}

[C++] 

#using <mscorlib.dll>
#using <system.dll>

using namespace System;
using namespace System::Reflection;
using namespace System::Text::RegularExpressions;

int main()
{
   // Get the type of 'System::Object'.
   Type* myType = __typeof(System::Object);

   // Get the path of 'System.dll'.
   String* system = Regex::Replace(myType->Assembly->CodeBase, S"mscorlib.dll", S"System.dll");
   system = Regex::Replace(system, S"file:///", S"");

   // Get the assembly information and display to the console.
   AssemblyName* myAssemblyName = AssemblyName::GetAssemblyName(system);
   Console::WriteLine(S"\nDisplaying the assembly information of 'System.dll'\n");
   Console::WriteLine(myAssemblyName);
}

[JScript] JScript のサンプルはありません。Visual Basic、C#、および C++ のサンプルを表示するには、このページの左上隅にある言語のフィルタ ボタン 言語のフィルタ をクリックします。

必要条件

プラットフォーム: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 ファミリ

.NET Framework セキュリティ:

参照

AssemblyName クラス | AssemblyName メンバ | System.Reflection 名前空間