AssemblyName AssemblyName AssemblyName AssemblyName Class

定义

完整描述程序集的唯一标识。Describes an assembly's unique identity in full.

public ref class AssemblyName sealed : ICloneable, System::Runtime::InteropServices::_AssemblyName, System::Runtime::Serialization::IDeserializationCallback, System::Runtime::Serialization::ISerializable
[System.Runtime.InteropServices.ClassInterface(System.Runtime.InteropServices.ClassInterfaceType.None)]
[System.Runtime.InteropServices.ComVisible(true)]
[System.Serializable]
public sealed class AssemblyName : ICloneable, System.Runtime.InteropServices._AssemblyName, System.Runtime.Serialization.IDeserializationCallback, System.Runtime.Serialization.ISerializable
type AssemblyName = class
    interface ICloneable
    interface ISerializable
    interface IDeserializationCallback
    interface _AssemblyName
Public NotInheritable Class AssemblyName
Implements _AssemblyName, ICloneable, IDeserializationCallback, ISerializable
继承
AssemblyNameAssemblyNameAssemblyNameAssemblyName
属性
实现

示例

此示例演示如何使用各种反射类来分析包含在程序集中的元数据。This example shows how to use various reflection classes to analyze the metadata contained in an assembly.

using namespace System;
using namespace System::Reflection;

static void Display(Int32 indent, String^ format, ... array<Object^>^param) 
{
    Console::Write("{0}", gcnew String (' ', indent));
    Console::WriteLine(format, param);
}
	
// Displays the custom attributes applied to the specified member.
static void DisplayAttributes(Int32 indent, MemberInfo^ mi)
{
    // Get the set of custom attributes; if none exist, just return.
    array<Object^>^attrs = mi->GetCustomAttributes(false);
		
    if (attrs->Length==0)
    {
        return;          
    }
		
    // Display the custom attributes applied to this member.
    Display(indent+1, "Attributes:");
    for each ( Object^ o in attrs )
    {
        Display(indent*2, "{0}", o);
    }				
}

void main()
{
    try
    {
        // This variable holds the amount of indenting that 
        // should be used when displaying each line of information.
        Int32 indent = 0; 
        // Display information about the EXE assembly.
        Assembly^ a = System::Reflection::Assembly::GetExecutingAssembly();
		
        Display(indent, "Assembly identity={0}", gcnew array<Object^> {a->FullName});
        Display(indent+1, "Codebase={0}", gcnew array<Object^> {a->CodeBase});

        // Display the set of assemblies our assemblies reference.
  
        Display(indent, "Referenced assemblies:"); 

        for each ( AssemblyName^ an in a->GetReferencedAssemblies() )
        {
            Display(indent + 1, "Name={0}, Version={1}, Culture={2}, PublicKey token={3}", gcnew array<Object^> {an->Name, an->Version, an->CultureInfo, (BitConverter::ToString(an->GetPublicKeyToken()))});
        }
        Display(indent, "");  
        // Display information about each assembly loading into this AppDomain. 
        for each ( Assembly^ b in AppDomain::CurrentDomain->GetAssemblies()) 
        {
            Display(indent, "Assembly: {0}", gcnew array<Object^> {b});
            // Display information about each module of this assembly.
 
            for each ( Module^ m in b->GetModules(true) ) 
            {
                Display(indent+1, "Module: {0}", gcnew array<Object^> {m->Name});
            }
            // Display information about each type exported from this assembly.
           
            indent += 1; 
            for each ( Type^ t in b->GetExportedTypes() ) 
            {
                Display(0, "");  
                Display(indent, "Type: {0}", gcnew array<Object^> {t}); 

                // For each type, show its members & their custom attributes.
           
                indent += 1; 
                for each (MemberInfo^ mi in t->GetMembers() )
                {
                    Display(indent, "Member: {0}", gcnew array<Object^> {mi->Name}); 
                    DisplayAttributes(indent, mi);

                    // If the member is a method, display information about its parameters.         
                    if (mi->MemberType==MemberTypes::Method) 
                    {
					
                        for each ( ParameterInfo^ pi in (((MethodInfo^) mi)->GetParameters()))
                        {
                            Display(indent+1, "Parameter: Type={0}, Name={1}", gcnew array<Object^> {pi->ParameterType, pi->Name}); 
                        }
                    }

                    // If the member is a property, display information about the property's accessor methods.
                    if (mi->MemberType==MemberTypes::Property) 
                    {
                        for each ( MethodInfo^ am in (((PropertyInfo^) mi)->GetAccessors()) )
                        {
                            Display(indent+1, "Accessor method: {0}", gcnew array<Object^> {am});
                        }
                    }
                }
                // Display a formatted string indented by the specified amount.               
                indent -= 1;
            }
            indent -= 1;
        }
    }
    catch (Exception^ e)
    {
        Console::WriteLine(e->Message);
    }
}

// The output shown below is abbreviated.
//
//Assembly identity=Reflection, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null
//  Codebase=file:///C:/Reflection.exe
//Referenced assemblies:
//  Name=mscorlib, Version=1.0.5000.0, Culture=, PublicKey token=B7-7A-5C-56-19-34-E0-89
//  Name=Microsoft.VisualBasic, Version=7.0.5000.0, Culture=, PublicKey token=B0-3F-5F-7F-11-D5-0A-3A
//
//Assembly: mscorlib, Version=1.0.5000.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
//  Module: mscorlib.dll
//  Module: prc.nlp
//  Module: prcp.nlp
//  Module: ksc.nlp
//  Module: ctype.nlp
//  Module: xjis.nlp
//  Module: bopomofo.nlp
//  Module: culture.nlp
//  Module: region.nlp
//  Module: sortkey.nlp
//  Module: charinfo.nlp
//  Module: big5.nlp
//  Module: sorttbls.nlp
//  Module: l_intl.nlp
//  Module: l_except.nlp
//
//  Type: System.Object
//    Member: GetHashCode
//    Member: Equals
//      Parameter: Type=System.Object, Name=obj
//    Member: ToString
//    Member: Equals
//      Parameter: Type=System.Object, Name=objA
//      Parameter: Type=System.Object, Name=objB
//    Member: ReferenceEquals
//      Parameter: Type=System.Object, Name=objA
//      Parameter: Type=System.Object, Name=objB
//    Member: GetType
//    Member: .ctor
//
//  Type: System.ICloneable
//    Member: Clone
//
//  Type: System.Collections.IEnumerable
//    Member: GetEnumerator
//      Attributes:
//        System.Runtime.InteropServices.DispIdAttribute
//
//  Type: System.Collections.ICollection
//    Member: get_IsSynchronized
//    Member: get_SyncRoot
//    Member: get_Count
//    Member: CopyTo
//      Parameter: Type=System.Array, Name=array
//      Parameter: Type=System.Int32, Name=index
//    Member: Count
//      Accessor method: Int32 get_Count()
//    Member: SyncRoot
//      Accessor method: System.Object get_SyncRoot()
//    Member: IsSynchronized
//      Accessor method: Boolean get_IsSynchronized()
//
using System;
using System.Reflection;

class Module1
{
    public static void Main()
    {
        // This variable holds the amount of indenting that 
        // should be used when displaying each line of information.
        Int32 indent = 0;
        // Display information about the EXE assembly.
        Assembly a = typeof(Module1).Assembly;
        Display(indent, "Assembly identity={0}", a.FullName);
        Display(indent+1, "Codebase={0}", a.CodeBase);

        // Display the set of assemblies our assemblies reference.
      
        Display(indent, "Referenced assemblies:");
        foreach (AssemblyName an in a.GetReferencedAssemblies() )
        {
             Display(indent + 1, "Name={0}, Version={1}, Culture={2}, PublicKey token={3}", an.Name, an.Version, an.CultureInfo.Name, (BitConverter.ToString (an.GetPublicKeyToken())));
        }
        Display(indent, "");
        
        // Display information about each assembly loading into this AppDomain.
        foreach (Assembly b in AppDomain.CurrentDomain.GetAssemblies())
        {
            Display(indent, "Assembly: {0}", b);

            // Display information about each module of this assembly.
            foreach ( Module m in b.GetModules(true) )
            {
                Display(indent+1, "Module: {0}", m.Name);
            }

            // Display information about each type exported from this assembly.
           
            indent += 1;
            foreach ( Type t in b.GetExportedTypes() )
            {
                Display(0, "");
                Display(indent, "Type: {0}", t);

                // For each type, show its members & their custom attributes.
           
                indent += 1;
                foreach (MemberInfo mi in t.GetMembers() )
                {
                    Display(indent, "Member: {0}", mi.Name);
                    DisplayAttributes(indent, mi);

                    // If the member is a method, display information about its parameters.
                    
                    if (mi.MemberType==MemberTypes.Method)
                    {
                        foreach ( ParameterInfo pi in ((MethodInfo) mi).GetParameters() )
                        {
                            Display(indent+1, "Parameter: Type={0}, Name={1}", pi.ParameterType, pi.Name);
                        }
                    }

                    // If the member is a property, display information about the property's accessor methods.
                    if (mi.MemberType==MemberTypes.Property)
                    {
                        foreach ( MethodInfo am in ((PropertyInfo) mi).GetAccessors() )
                        {
                            Display(indent+1, "Accessor method: {0}", am);
                        }
                    }
                }
                indent -= 1;
            }
            indent -= 1;
        }
    }

    // Displays the custom attributes applied to the specified member.
    public static void DisplayAttributes(Int32 indent, MemberInfo mi)
    {
        // Get the set of custom attributes; if none exist, just return.
        object[] attrs = mi.GetCustomAttributes(false);
        if (attrs.Length==0) {return;}

        // Display the custom attributes applied to this member.
        Display(indent+1, "Attributes:");
        foreach ( object o in attrs )
        {
            Display(indent+2, "{0}", o.ToString());
        }
    }

    // Display a formatted string indented by the specified amount.
    public static void Display(Int32 indent, string format, params object[] param) 

    {
        Console.Write(new string(' ', indent*2));
        Console.WriteLine(format, param);
    }
}

//The output shown below is abbreviated.
//
//Assembly identity=ReflectionCS, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null
//  Codebase=file:///C:/Documents and Settings/test/My Documents/Visual Studio 2005/Projects/Reflection/Reflection/obj/Debug/Reflection.exe
//Referenced assemblies:
//  Name=mscorlib, Version=2.0.0.0, Culture=, PublicKey token=B7-7A-5C-56-19-34-E0-89
//
//Assembly: mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
//  Module: mscorlib.dll
//  Module: mscorlib.dll
//  Module: mscorlib.dll
//  Module: mscorlib.dll
//  Module: mscorlib.dll
//  Module: mscorlib.dll
//  Module: mscorlib.dll
//  Module: mscorlib.dll
//  Module: mscorlib.dll
//  Module: mscorlib.dll
//  Module: mscorlib.dll
//  Module: mscorlib.dll
//  Module: mscorlib.dll
//  Module: mscorlib.dll
//
//  Type: System.Object
//    Member: GetType
//    Member: ToString
//    Member: Equals
//      Parameter: Type=System.Object, Name=obj
//    Member: Equals
//      Parameter: Type=System.Object, Name=objA
//      Parameter: Type=System.Object, Name=objB
//    Member: ReferenceEquals
//      Attributes:
//        System.Runtime.ConstrainedExecution.ReliabilityContractAttribute
//      Parameter: Type=System.Object, Name=objA
//      Parameter: Type=System.Object, Name=objB
//    Member: GetHashCode
//    Member: .ctor
//      Attributes:
//        System.Runtime.ConstrainedExecution.ReliabilityContractAttribute
//
//  Type: System.ICloneable
//    Member: Clone
//
//  Type: System.Collections.IEnumerable
//    Member: GetEnumerator
//      Attributes:
//        System.Runtime.InteropServices.DispIdAttribute
//
//  Type: System.Collections.ICollection
//    Member: CopyTo
//      Parameter: Type=System.Array, Name=array
//      Parameter: Type=System.Int32, Name=index
//    Member: get_Count
//    Member: get_SyncRoot
//    Member: get_IsSynchronized
//    Member: Count
//      Accessor method: Int32 get_Count()
//    Member: SyncRoot
//      Accessor method: System.Object get_SyncRoot()
//    Member: IsSynchronized
//      Accessor method: Boolean get_IsSynchronized()
//
//  Type: System.Collections.IList
//    Member: get_Item
//      Parameter: Type=System.Int32, Name=index
//    Member: set_Item
//      Parameter: Type=System.Int32, Name=index
//      Parameter: Type=System.Object, Name=value
//    Member: Add
//      Parameter: Type=System.Object, Name=value
//    Member: Contains
//      Parameter: Type=System.Object, Name=value
//    Member: Clear
//    Member: get_IsReadOnly
//    Member: get_IsFixedSize
//    Member: IndexOf
//      Parameter: Type=System.Object, Name=value
//    Member: Insert
//      Parameter: Type=System.Int32, Name=index
//      Parameter: Type=System.Object, Name=value
//    Member: Remove
//      Parameter: Type=System.Object, Name=value
//    Member: RemoveAt
//      Parameter: Type=System.Int32, Name=index
//    Member: Item
//      Accessor method: System.Object get_Item(Int32)
//      Accessor method: Void set_Item(Int32, System.Object)
//    Member: IsReadOnly
//      Accessor method: Boolean get_IsReadOnly()
//    Member: IsFixedSize
//      Accessor method: Boolean get_IsFixedSize()
//
//  Type: System.Array
//    Member: IndexOf
//      Parameter: Type=T[], Name=array
//      Parameter: Type=T, Name=value
//    Member: AsReadOnly
//      Parameter: Type=T[], Name=array
//    Member: Resize
//      Attributes:
//        System.Runtime.ConstrainedExecution.ReliabilityContractAttribute
//      Parameter: Type=T[]&, Name=array
//      Parameter: Type=System.Int32, Name=newSize
//    Member: BinarySearch
//      Attributes:
//        System.Runtime.ConstrainedExecution.ReliabilityContractAttribute
//      Parameter: Type=T[], Name=array
//      Parameter: Type=T, Name=value
//    Member: BinarySearch
//      Attributes:
//        System.Runtime.ConstrainedExecution.ReliabilityContractAttribute
//      Parameter: Type=T[], Name=array
//      Parameter: Type=T, Name=value
//      Parameter: Type=System.Collections.Generic.IComparer`1[T], Name=comparer
Imports System.Reflection

Module Module1
    Sub Main()
        ' This variable holds the amount of indenting that 
        ' should be used when displaying each line of information.
        Dim indent As Int32 = 0
        ' Display information about the EXE assembly.
        Dim a As Assembly = GetType(Module1).Assembly
        Display(indent, "Assembly identity={0}", a.FullName)
        Display(indent + 1, "Codebase={0}", a.CodeBase)

        ' Display the set of assemblies our assemblies reference.
        Dim an As AssemblyName
        Display(indent, "Referenced assemblies:")
        For Each an In a.GetReferencedAssemblies()
            Display(indent + 1, "Name={0}, Version={1}, Culture={2}, PublicKey token={3}", _
                an.Name, an.Version, an.CultureInfo.Name, BitConverter.ToString(an.GetPublicKeyToken))
        Next
        Display(indent, "")

        ' Display information about each assembly loading into this AppDomain.
        For Each a In AppDomain.CurrentDomain.GetAssemblies()
            Display(indent, "Assembly: {0}", a)

            ' Display information about each module of this assembly.
            Dim m As [Module]
            For Each m In a.GetModules(True)
                Display(indent + 1, "Module: {0}", m.Name)
            Next

            ' Display information about each type exported from this assembly.
            Dim t As Type
            indent += 1
            For Each t In a.GetExportedTypes()
                Display(0, "")
                Display(indent, "Type: {0}", t)

                ' For each type, show its members & their custom attributes.
                Dim mi As MemberInfo
                indent += 1
                For Each mi In t.GetMembers()
                    Display(indent, "Member: {0}", mi.Name)
                    DisplayAttributes(indent, mi)

                    ' If the member is a method, display information about its parameters.
                    Dim pi As ParameterInfo
                    If mi.MemberType = MemberTypes.Method Then
                        For Each pi In CType(mi, MethodInfo).GetParameters()
                            Display(indent + 1, "Parameter: Type={0}, Name={1}", pi.ParameterType, pi.Name)
                        Next
                    End If

                    ' If the member is a property, display information about the property's accessor methods.
                    If mi.MemberType = MemberTypes.Property Then
                        Dim am As MethodInfo
                        For Each am In CType(mi, PropertyInfo).GetAccessors()
                            Display(indent + 1, "Accessor method: {0}", am)
                        Next
                    End If
                Next
                indent -= 1
            Next
            indent -= 1
        Next
    End Sub

    ' Displays the custom attributes applied to the specified member.
    Sub DisplayAttributes(ByVal indent As Int32, ByVal mi As MemberInfo)
        ' Get the set of custom attributes; if none exist, just return.
        Dim attrs() As Object = mi.GetCustomAttributes(False)
        If attrs.Length = 0 Then Return

        ' Display the custom attributes applied to this member.
        Display(indent + 1, "Attributes:")
        Dim o As Object
        For Each o In attrs
            Display(indent + 2, "{0}", o.ToString())
        Next
    End Sub

    ' Display a formatted string indented by the specified amount.
    Sub Display(ByVal indent As Int32, ByVal format As String, ByVal ParamArray params() As Object)
        Console.Write(New String(" "c, indent * 2))
        Console.WriteLine(format, params)
    End Sub
End Module

'The output shown below is abbreviated.
'
'Assembly identity=Reflection, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null
'  Codebase=file:///C:/Reflection.exe
'Referenced assemblies:
'  Name=mscorlib, Version=1.0.5000.0, Culture=, PublicKey token=B7-7A-5C-56-19-34-E0-89
'  Name=Microsoft.VisualBasic, Version=7.0.5000.0, Culture=, PublicKey token=B0-3F-5F-7F-11-D5-0A-3A
'
'Assembly: mscorlib, Version=1.0.5000.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
'  Module: mscorlib.dll
'  Module: prc.nlp
'  Module: prcp.nlp
'  Module: ksc.nlp
'  Module: ctype.nlp
'  Module: xjis.nlp
'  Module: bopomofo.nlp
'  Module: culture.nlp
'  Module: region.nlp
'  Module: sortkey.nlp
'  Module: charinfo.nlp
'  Module: big5.nlp
'  Module: sorttbls.nlp
'  Module: l_intl.nlp
'  Module: l_except.nlp
'
'  Type: System.Object
'    Member: GetHashCode
'    Member: Equals
'      Parameter: Type=System.Object, Name=obj
'    Member: ToString
'    Member: Equals
'      Parameter: Type=System.Object, Name=objA
'      Parameter: Type=System.Object, Name=objB
'    Member: ReferenceEquals
'      Parameter: Type=System.Object, Name=objA
'      Parameter: Type=System.Object, Name=objB
'    Member: GetType
'    Member: .ctor
'
'  Type: System.ICloneable
'    Member: Clone
'
'  Type: System.Collections.IEnumerable
'    Member: GetEnumerator
'      Attributes:
'        System.Runtime.InteropServices.DispIdAttribute
'
'  Type: System.Collections.ICollection
'    Member: get_IsSynchronized
'    Member: get_SyncRoot
'    Member: get_Count
'    Member: CopyTo
'      Parameter: Type=System.Array, Name=array
'      Parameter: Type=System.Int32, Name=index
'    Member: Count
'      Accessor method: Int32 get_Count()
'    Member: SyncRoot
'      Accessor method: System.Object get_SyncRoot()
'    Member: IsSynchronized
'      Accessor method: Boolean get_IsSynchronized()
'

注解

AssemblyName对象包含有关程序集,可用于对该程序集绑定信息。The AssemblyName object contains information about an assembly, which you can use to bind to that assembly. 程序集的标识由以下内容组成:An assembly's identity consists of the following:

  • 简单名称。Simple name.

  • 版本号。Version number.

  • 加密密钥对。Cryptographic key pair.

  • 支持的区域性。Supported culture.

简单名称通常是不带扩展名的清单文件的文件名。The simple name is typically the file name for the manifest file without its extension. 密钥对包含公钥和私钥的密钥,用于创建强名称签名的程序集。The key pair includes a public and private key, used to create strong-name signatures for assemblies.

支持公共语言运行时的所有编译器将都发出嵌套类的简单名称和反射构造查询时,根据以下约定的重整的名称。All compilers that support the common language runtime will emit the simple name of a nested class, and reflection constructs a mangled name when queried, in accordance with the following conventions.

分隔符Delimiter 含义Meaning
反斜杠 (\)Backslash (\) 转义符。Escape character.
逗号 (,)Comma (,) 程序集名称前面。Precedes the assembly name.
加号 (+)Plus sign (+) 位于嵌套的类。Precedes a nested class.

例如,一个类的完全限定的名称可能如下所示:For example, the fully qualified name for a class might look like this:

ContainingClass + NestedClass MyAssemblyContainingClass+NestedClass,MyAssembly

一个"+ +"变为"\+\+",和一个"\"变为"\\"。A "++" becomes "\+\+", and a "\" becomes "\\".

可以保持此限定的名,并在以后使用它来加载TypeThis qualified name can be persisted and later used to load the Type. 若要搜索并加载Type,使用GetType使用类型名称只或用程序集限定的类型名称。To search for and load a Type, use GetType either with the type name only or with the assembly qualified type name. GetType 使用类型名称只会查找Type中调用方的程序集,然后在系统程序集。GetType with the type name only will look for the Type in the caller's assembly and then in the System assembly. GetType 使用程序集限定的类型名称将寻找Type在任何程序集中。GetType with the assembly qualified type name will look for the Type in any assembly.

完全指定AssemblyName必须具有主版本、 次版本、 内部版本号和修订号参数的名称、 区域性、 公钥标记。A fully specified AssemblyName must have the name, culture, public key or public key token, major version, minor version, build number, and revision number parameters. 最后一个四个参数封装在Version类型。The last four are packaged in the Version type.

若要创建一个简单的名称,创建AssemblyName对象使用默认构造函数,并将NameTo create a simple name, create an AssemblyName object using the default constructor and set the Name. 其他属性是可选的。The other properties are optional.

若要创建完整的强名称,创建AssemblyName对象使用默认构造函数,并将NameKeyPairTo create a full strong name, create an AssemblyName object using the default constructor and set the Name and KeyPair. 其他属性是可选的。The other properties are optional. 使用SetPublicKeySetPublicKeyToken设置公用密钥和强名称。Use SetPublicKey and SetPublicKeyToken to set the public key and the strong name. 强名称签名始终使用SHA1哈希算法。The strong name signing always uses the SHA1 hash algorithm.

若要确保正确构造名称,请使用以下属性:To ensure that the names are constructed correctly, use the following properties:

此外可以通过使用获取名称/l选项与Gacutil.exe (全局程序集缓存工具)You can also get the name by using the /l option with the Gacutil.exe (Global Assembly Cache Tool)

对于部分指定的强名称,创建AssemblyName对象使用默认构造函数,并且设置的名称和公钥。For a partially specified strong name, create an AssemblyName object using the default constructor and set the name and public key. 使用此类创建的程序集AssemblyName更高版本使用程序集链接器 (Al.exe) 进行签名。An assembly created using such an AssemblyName can be signed later using the Assembly Linker (Al.exe).

可以指定一个公钥和一个KeyPair具有不一致的值。It is possible to specify a public key and a KeyPair with inconsistent values. 这可以是开发人员方案中非常有用。This can be useful in developer scenarios. 中的公共密钥在这种情况下,通过检索GetPublicKey指定正确的公共密钥,whileKeyPair指定在开发过程中使用的公钥和私钥键。In this case, the public key retrieved with GetPublicKey specifies the correct public key, while the KeyPair specifies the public and private keys used during development. 当运行时检测到不匹配KeyPair和公钥,它会查找在注册表中正确的密钥相匹配的公钥。When the runtime detects a mismatch between the KeyPair and the public key, it looks up in the registry the correct key that matches the public key.

显示名称的格式AssemblyName是以逗号分隔的名称,按如下所示开头的 Unicode 字符串:The format of the display name of an AssemblyName is a comma-delimited Unicode string that begins with the name, as follows:

Name <,Culture = CultureInfo> <,Version = Major.Minor.Build.Revision> <, StrongName> <,PublicKeyToken> '\0'

Name 是文本的程序集的名称。Name is the textual name of the assembly. CultureInfo 是 RFC1766 格式定义区域性。CultureInfo is the RFC1766-format-defined culture. Major``MinorBuild,和Revision是主版本、 次版本、 内部版本号和修订号的程序集。Major, Minor, Build, and Revision are the major version, minor version, build number, and revision number of the assembly. StrongName 为十六进制编码低序位 64 位的使用 sha-1 哈希算法生成的公钥和指定的公钥的哈希值SetPublicKeyStrongName is the hexadecimal-encoded low-order 64 bits of the hash value of the public key generated using the SHA-1 hashing algorithm and the public key specified by SetPublicKey. PublicKeyToken 是由指定的十六进制编码的公共密钥SetPublicKeyPublicKeyToken is the hexadecimal-encoded public key specified by SetPublicKey.

十六进制编码被定义为每个字节的二进制对象转换为两个十六进制字符,按照从最低到最高有效字节。Hexadecimal encoding is defined as the conversion of each byte of a binary object to two hexadecimal characters, progressing from least to most significant byte. 必要时,将添加附加的显示值。Additional display values will be added as deemed necessary.

如果已知的完整公钥,公钥可能替换为 StrongName。If the full public key is known, then PublicKey may be substituted for StrongName.

另请注意,除Name,必须先出现,参数的词汇顺序并不重要。Also note that except for Name, which must come first, the lexical order of parameters is unimportant. 但是,任何参数 (VersionCultureStrongNamePublicKey) 不是专门,则可以认为,都可以省略和AssemblyName然后将被视为部分。However, any parameter (Version, Culture, StrongName or PublicKey) not specifically set is considered to be omitted, and the AssemblyName is then considered partial. 指定部分的信息时,必须按前面所述的顺序指定 Name 参数。When specifying partial information, Name parameters must be specified in the order described above.

提供显示名称,约定时StrongName =nullPublicKey= null表示需要绑定并与简单命名程序集相匹配。When supplying a display name, the convention StrongName =null or PublicKey= null indicates that binding and matching against a simply named assembly is required. 此外,约定Culture= ""(双引号表示空字符串) 指示针对默认区域性的匹配。Additionally, the convention Culture= "" (double quote representing an empty string) indicates matching against the default culture.

下面的示例演示AssemblyName为具有默认区域性的简单命名程序集。The following example shows an AssemblyName for a simply named assembly with default culture.

ExampleAssembly, Culture=""  

下面的示例演示区域性为“en”的强名称程序集的完全指定的引用。The following example shows a fully specified reference for a strongly named assembly with culture "en".

ExampleAssembly, Version=1.0.0.0, Culture=en, PublicKeyToken=a5d015c7d5a0b012  

构造函数

AssemblyName() AssemblyName() AssemblyName() AssemblyName()

初始化 AssemblyName 类的新实例。Initializes a new instance of the AssemblyName class.

AssemblyName(String) AssemblyName(String) AssemblyName(String) AssemblyName(String)

使用指定的显示名称初始化 AssemblyName 类的新实例。Initializes a new instance of the AssemblyName class with the specified display name.

属性

CodeBase CodeBase CodeBase CodeBase

获取或设置程序集的 URL 位置。Gets or sets the location of the assembly as a URL.

ContentType ContentType ContentType ContentType

获取或设置指示程序集包含的内容类型的值。Gets or sets a value that indicates what type of content the assembly contains.

CultureInfo CultureInfo CultureInfo CultureInfo

获取或设置程序集支持的区域性。Gets or sets the culture supported by the assembly.

CultureName CultureName CultureName CultureName

获取或设置与此程序集关联的区域性名称。Gets or sets the name of the culture associated with the assembly.

EscapedCodeBase EscapedCodeBase EscapedCodeBase EscapedCodeBase

获取 URI,包括表示基本代码的转义符。Gets the URI, including escape characters, that represents the codebase.

Flags Flags Flags Flags

获取或设置该程序集的属性。Gets or sets the attributes of the assembly.

FullName FullName FullName FullName

获取程序集的全名(也称为显示名称)。Gets the full name of the assembly, also known as the display name.

HashAlgorithm HashAlgorithm HashAlgorithm HashAlgorithm

获取或设置程序集清单使用的哈希算法。Gets or sets the hash algorithm used by the assembly manifest.

KeyPair KeyPair KeyPair KeyPair

获取或设置用于为程序集创建强名称签名的加密公钥/私钥对。Gets or sets the public and private cryptographic key pair that is used to create a strong name signature for the assembly.

Name Name Name Name

获取或设置程序集的简单名称。Gets or sets the simple name of the assembly. 这通常(但不一定)是程序集的清单文件的文件名,不包括其扩展名。This is usually, but not necessarily, the file name of the manifest file of the assembly, minus its extension.

ProcessorArchitecture ProcessorArchitecture ProcessorArchitecture ProcessorArchitecture

获取或设置一个值,该值标识可执行文件的目标平台的处理器和每字位数。Gets or sets a value that identifies the processor and bits-per-word of the platform targeted by an executable.

Version Version Version Version

获取或设置程序集的主版本号、次版本号、内部版本号和修订号。Gets or sets the major, minor, build, and revision numbers of the assembly.

VersionCompatibility VersionCompatibility VersionCompatibility VersionCompatibility

获取或设置与程序集同其他程序集的兼容性相关的信息。Gets or sets the information related to the assembly's compatibility with other assemblies.

方法

Clone() Clone() Clone() Clone()

制作此 AssemblyName 对象的副本。Makes a copy of this AssemblyName object.

Equals(Object) Equals(Object) Equals(Object) Equals(Object)

确定指定的对象是否等于当前对象。Determines whether the specified object is equal to the current object.

(Inherited from Object)
GetAssemblyName(String) GetAssemblyName(String) GetAssemblyName(String) GetAssemblyName(String)

获取给定文件的 AssemblyNameGets the AssemblyName for a given file.

GetHashCode() GetHashCode() GetHashCode() GetHashCode()

作为默认哈希函数。Serves as the default hash function.

(Inherited from Object)
GetObjectData(SerializationInfo, StreamingContext) GetObjectData(SerializationInfo, StreamingContext) GetObjectData(SerializationInfo, StreamingContext) GetObjectData(SerializationInfo, StreamingContext)

获取序列化信息,其中包含重新创建此 AssemblyName 实例所需的所有数据。Gets serialization information with all the data needed to recreate an instance of this AssemblyName.

GetPublicKey() GetPublicKey() GetPublicKey() GetPublicKey()

获取程序集的公钥。Gets the public key of the assembly.

GetPublicKeyToken() GetPublicKeyToken() GetPublicKeyToken() GetPublicKeyToken()

获取公钥标记,该标记为应用程序或程序集签名时所用公钥的 SHA-1 哈希值的最后 8 个字节。Gets the public key token, which is the last 8 bytes of the SHA-1 hash of the public key under which the application or assembly is signed.

GetType() GetType() GetType() GetType()

获取当前实例的 TypeGets the Type of the current instance.

(Inherited from Object)
MemberwiseClone() MemberwiseClone() MemberwiseClone() MemberwiseClone()

创建当前 Object 的浅表副本。Creates a shallow copy of the current Object.

(Inherited from Object)
OnDeserialization(Object) OnDeserialization(Object) OnDeserialization(Object) OnDeserialization(Object)

实现 ISerializable 接口,并在完成反序列化后由反序列化事件回调。Implements the ISerializable interface and is called back by the deserialization event when deserialization is complete.

ReferenceMatchesDefinition(AssemblyName, AssemblyName) ReferenceMatchesDefinition(AssemblyName, AssemblyName) ReferenceMatchesDefinition(AssemblyName, AssemblyName) ReferenceMatchesDefinition(AssemblyName, AssemblyName)

返回指示两个程序集名称是否相同的值。Returns a value indicating whether two assembly names are the same. 该比较基于简单的程序集名称。The comparison is based on the simple assembly names.

SetPublicKey(Byte[]) SetPublicKey(Byte[]) SetPublicKey(Byte[]) SetPublicKey(Byte[])

设置用于标识程序集的公钥。Sets the public key identifying the assembly.

SetPublicKeyToken(Byte[]) SetPublicKeyToken(Byte[]) SetPublicKeyToken(Byte[]) SetPublicKeyToken(Byte[])

设置公钥标记,该标记为应用程序或程序集签名时所用公钥的 SHA-1 哈希值的最后 8 个字节。Sets the public key token, which is the last 8 bytes of the SHA-1 hash of the public key under which the application or assembly is signed.

ToString() ToString() ToString() ToString()

返回程序集的全名,即所谓的显示名称。Returns the full name of the assembly, also known as the display name.

显式界面实现

_AssemblyName.GetIDsOfNames(Guid, IntPtr, UInt32, UInt32, IntPtr) _AssemblyName.GetIDsOfNames(Guid, IntPtr, UInt32, UInt32, IntPtr) _AssemblyName.GetIDsOfNames(Guid, IntPtr, UInt32, UInt32, IntPtr) _AssemblyName.GetIDsOfNames(Guid, IntPtr, UInt32, UInt32, IntPtr)

将一组名称映射为对应的一组调度标识符。Maps a set of names to a corresponding set of dispatch identifiers.

_AssemblyName.GetTypeInfo(UInt32, UInt32, IntPtr) _AssemblyName.GetTypeInfo(UInt32, UInt32, IntPtr) _AssemblyName.GetTypeInfo(UInt32, UInt32, IntPtr) _AssemblyName.GetTypeInfo(UInt32, UInt32, IntPtr)

检索对象的类型信息,然后可以使用该信息获取接口的类型信息。Retrieves the type information for an object, which can then be used to get the type information for an interface.

_AssemblyName.GetTypeInfoCount(UInt32) _AssemblyName.GetTypeInfoCount(UInt32) _AssemblyName.GetTypeInfoCount(UInt32) _AssemblyName.GetTypeInfoCount(UInt32)

检索对象提供的类型信息接口的数量(0 或 1)。Retrieves the number of type information interfaces that an object provides (either 0 or 1).

_AssemblyName.Invoke(UInt32, Guid, UInt32, Int16, IntPtr, IntPtr, IntPtr, IntPtr) _AssemblyName.Invoke(UInt32, Guid, UInt32, Int16, IntPtr, IntPtr, IntPtr, IntPtr) _AssemblyName.Invoke(UInt32, Guid, UInt32, Int16, IntPtr, IntPtr, IntPtr, IntPtr) _AssemblyName.Invoke(UInt32, Guid, UInt32, Int16, IntPtr, IntPtr, IntPtr, IntPtr)

提供对某一对象公开的属性和方法的访问。Provides access to properties and methods exposed by an object.

适用于

另请参阅