如何比较两个程序集实例?

时间:2022-08-31 23:05:51

How do I compare two AssemblyName instances to figure out whether they represent the same assembly? The 'Equals' method isn't overriden.

我如何比较两个程序集实例来判断它们是否代表相同的程序集?“等”法并不过分。

One way I can think of is compare the 'ToString()' results of both the instances but I would prefer an 'Equals' syntax since I need to prepare a list (List) of 'unique' AssemblyName instances and would like to use the 'Contains(AssemblyName item)' method.

我能想到的一种方法是比较两个实例的'ToString()'结果,但我更喜欢'Equals'语法,因为我需要准备一个'unique'程序集名称实例的列表(列表),并希望使用'Contains(程序集名称项)'方法。

2 个解决方案

#1


6  

As long as you are using strongly-named assemblies, comparing the output of the ToString method would be fine, as it outputs the full name of the assembly, which is supposed to be consistent and seems to be culture-invariant.

只要您使用的是强命名的程序集,比较ToString方法的输出就可以了,因为它输出了程序集的全称,这应该是一致的,而且似乎是不变量的。

If the assemblies are not strong-named, then one can easily create another assembly with the same name and version number/culture and it would have the same assembly name as yours.

如果程序集不是强命名的,那么可以很容易地创建具有相同名称和版本号/文化的另一个程序集,并且它将具有与您的相同的程序集名称。

One thing to note though, because the assembly names are the same doesn't mean that the assemblies are the same physical identity; location is not part of the assembly name.

有一点需要注意,因为程序集的名称是相同的并不意味着程序集是相同的物理标识;位置不是程序集名称的一部分。

#2


2  

I would compare the AssemblyName.FullName property, as it represents the actual version specific identity of the assembly.

我比较一下程序集。FullName属性,因为它表示程序集的实际版本特定标识。

#1


6  

As long as you are using strongly-named assemblies, comparing the output of the ToString method would be fine, as it outputs the full name of the assembly, which is supposed to be consistent and seems to be culture-invariant.

只要您使用的是强命名的程序集,比较ToString方法的输出就可以了,因为它输出了程序集的全称,这应该是一致的,而且似乎是不变量的。

If the assemblies are not strong-named, then one can easily create another assembly with the same name and version number/culture and it would have the same assembly name as yours.

如果程序集不是强命名的,那么可以很容易地创建具有相同名称和版本号/文化的另一个程序集,并且它将具有与您的相同的程序集名称。

One thing to note though, because the assembly names are the same doesn't mean that the assemblies are the same physical identity; location is not part of the assembly name.

有一点需要注意,因为程序集的名称是相同的并不意味着程序集是相同的物理标识;位置不是程序集名称的一部分。

#2


2  

I would compare the AssemblyName.FullName property, as it represents the actual version specific identity of the assembly.

我比较一下程序集。FullName属性,因为它表示程序集的实际版本特定标识。