从强名称获取程序集版本
将扩展方法作为扩展名和常规方法调用的示例。
public Class MyClass
Sub Main()
'Extension called directly on the object.
Dim Version = Assembly.GetExecutingAssembly.GetVersionFromAssembly()
'Called as a regular method.
Dim Ver = GetVersionFromAssembly(SomeOtherAssembly)
End Sub
End Class
模块中的扩展方法。如果将扩展编译为 dll 并将在另一个程序集中引用,则将模块设为公共。
Public Module Extensions
''' <summary>
''' Returns the version number from the specified assembly using the assembly's strong name.
''' </summary>
''' <param name="Assy">[Assembly] Assembly to get the version info from.</param>
''' <returns>[String]</returns>
<Extension>
Friend Function GetVersionFromAssembly(ByVal Assy As Assembly) As String
Return Split(Split(Assy.FullName,",")(1),"=")(1)
End Function
End Module