⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 assemblydeclaration.vb

📁 大名鼎鼎的mono是.NET平台的跨平台(支持linux
💻 VB
📖 第 1 页 / 共 3 页
字号:
            keyfile = Compiler.CommandLine.KeyFile        End If        For Each attri As Attribute In Me.Attributes            Dim attribType As Type            attribType = attri.ResolvedType            If Helper.CompareType(attribType, Compiler.TypeCache.System_Reflection_AssemblyVersionAttribute) Then                SetVersion(result, attri, attri.Location)            ElseIf Helper.CompareType(attribType, Compiler.TypeCache.System_Reflection_AssemblyKeyFileAttribute) Then                If keyfile = String.Empty Then keyfile = TryCast(attri.Arguments()(0), String)            ElseIf Helper.CompareType(attribType, Compiler.TypeCache.System_Reflection_AssemblyKeyNameAttribute) Then                keyname = TryCast(attri.Arguments()(0), String)            ElseIf Helper.CompareType(attribType, Compiler.TypeCache.System_Reflection_AssemblyDelaySignAttribute) Then                delaysign = CBool(attri.Arguments()(0))            End If        Next        If keyfile <> String.Empty Then            If SignWithKeyFile(result, keyfile, delaysign) = False Then                Return result            End If        End If        Return result    End Function    Private Function SignWithKeyFile(ByVal result As AssemblyName, ByVal KeyFile As String, ByVal DelaySign As Boolean) As Boolean        Dim filename As String        filename = IO.Path.GetFullPath(KeyFile)#If DEBUG Then        Compiler.Report.WriteLine("Signing with file: " & filename)#End If        If IO.File.Exists(filename) = False Then            Helper.AddError("Can't find keyfile: " & filename)            Return False        End If        Using stream As New IO.FileStream(filename, IO.FileMode.Open, IO.FileAccess.Read)            Dim snkeypair() As Byte            ReDim snkeypair(CInt(stream.Length - 1))            stream.Read(snkeypair, 0, snkeypair.Length)            If Helper.IsOnMono Then                SignWithKeyFileMono(result, filename, DelaySign, snkeypair)            Else                If DelaySign Then                    result.SetPublicKey(snkeypair)                Else                    result.KeyPair = New StrongNameKeyPair(snkeypair)                End If            End If        End Using        Return True    End Function    Private Function SignWithKeyFileMono(ByVal result As AssemblyName, ByVal KeyFile As String, ByVal DelaySign As Boolean, ByVal blob As Byte()) As Boolean        Dim CryptoConvert As Type        Dim FromCapiKeyBlob As MethodInfo        Dim ToCapiPublicKeyBlob As MethodInfo        Dim FromCapiPrivateKeyBlob As MethodInfo        Dim RSA As Type        Dim mscorlib As Assembly = GetType(Integer).Assembly#If DEBUG Then        Compiler.Report.WriteLine("Signing on Mono")#End If        Try            RSA = mscorlib.GetType("System.Security.Cryptography.RSA")            CryptoConvert = mscorlib.GetType("Mono.Security.Cryptography.CryptoConvert")            FromCapiKeyBlob = CryptoConvert.GetMethod("FromCapiKeyBlob", BindingFlags.Public Or BindingFlags.Static Or BindingFlags.ExactBinding, Nothing, New Type() {Compiler.TypeCache.System_Byte_Array}, Nothing)            ToCapiPublicKeyBlob = CryptoConvert.GetMethod("ToCapiPublicKeyBlob", BindingFlags.Static Or BindingFlags.Public Or BindingFlags.ExactBinding, Nothing, New Type() {RSA}, Nothing)            FromCapiPrivateKeyBlob = CryptoConvert.GetMethod("FromCapiPrivateKeyBlob", BindingFlags.Static Or BindingFlags.Public Or BindingFlags.ExactBinding, Nothing, New Type() {Compiler.TypeCache.System_Byte_Array}, Nothing)            If DelaySign Then                If blob.Length = 16 Then                    result.SetPublicKey(blob)#If DEBUG Then                    Compiler.Report.WriteLine("Delay signed 1")#End If                Else                    Dim publickey() As Byte                    Dim fromCapiResult As Object                    Dim publicKeyHeader As Byte() = New Byte() {&H0, &H24, &H0, &H0, &H4, &H80, &H0, &H0, &H94, &H0, &H0, &H0}                    Dim encodedPublicKey() As Byte                    fromCapiResult = FromCapiKeyBlob.Invoke(Nothing, New Object() {blob})                    publickey = CType(ToCapiPublicKeyBlob.Invoke(Nothing, New Object() {fromCapiResult}), Byte())                    ReDim encodedPublicKey(11 + publickey.Length)                    Buffer.BlockCopy(publicKeyHeader, 0, encodedPublicKey, 0, 12)                    Buffer.BlockCopy(publickey, 0, encodedPublicKey, 12, publickey.Length)                    result.SetPublicKey(encodedPublicKey)#If DEBUG Then                    Compiler.Report.WriteLine("Delay signed 2")#End If                End If            Else                FromCapiPrivateKeyBlob.Invoke(Nothing, New Object() {blob})                result.KeyPair = New StrongNameKeyPair(blob)            End If        Catch ex As Exception            Helper.AddError("Invalid key file: " & KeyFile & ", got error: " & ex.Message)        End Try    End Function    Private Function SetVersion(ByVal Name As AssemblyName, ByVal Attribute As Attribute, ByVal Location As Span) As Boolean        Dim result As Version        Dim version As String = ""        If Attribute.Arguments IsNot Nothing AndAlso Attribute.Arguments.Length = 1 Then            version = TryCast(Attribute.Arguments()(0), String)        Else            Return ShowInvalidVersionMessage(version, Location)        End If        Try            Dim parts() As String            Dim major, minor, build, revision As UShort            parts = version.Split("."c)            If parts.Length > 4 Then                Return ShowInvalidVersionMessage(version, Location)            End If            If Not UShort.TryParse(parts(0), major) Then                Return ShowInvalidVersionMessage(version, Location)            End If            If Not UShort.TryParse(parts(1), minor) Then                Return ShowInvalidVersionMessage(version, Location)            End If            If parts.Length < 3 Then                'Use 0            ElseIf parts(2) = "*" Then                build = CUShort((Date.Now - New Date(2000, 1, 1)).TotalDays)                revision = CUShort((Date.Now.Hour * 3600 + Date.Now.Minute * 60 + Date.Now.Second) / 2)            ElseIf Not UShort.TryParse(parts(2), build) Then                Return ShowInvalidVersionMessage(version, Location)            End If            If parts.Length < 4 Then                'Use 0            ElseIf parts.Length > 3 Then                If parts(3) = "*" Then                    revision = CUShort((Date.Now.Hour * 3600 + Date.Now.Minute * 60 + Date.Now.Second) / 2)                ElseIf Not UShort.TryParse(parts(3), revision) Then                    Return ShowInvalidVersionMessage(version, Location)                End If            End If            result = New Version(major, minor, build, revision)        Catch ex As Exception            Return ShowInvalidVersionMessage(version, Location)        End Try        Name.Version = result        Return True    End Function    Private Function ShowInvalidVersionMessage(ByVal Version As String, ByVal Location As Span) As Boolean        Compiler.Report.ShowMessage(Messages.VBNC30129, Location, "System.Reflection.AssemblyVersionAttribute", Version)        Return False    End Function    ''' <summary>    ''' - CreateType() is called on the builders for all classes, modules, structures, interfaces and delegates.    ''' - Classes, modules, structures, enums, delegates, interfaces should implement IType.CreateType    ''' </summary>    ''' <returns></returns>    ''' <remarks></remarks>    Function CreateTypes() As Boolean        Dim result As Boolean = True        Dim exs As New Generic.List(Of Exception)        Dim tps As New Generic.List(Of TypeDeclaration)        For Each type As TypeDeclaration In m_TypeDeclarations#If EXTENDEDDEBUG Then            Dim iCount As Integer            iCount += 1            Try                System.Console.ForegroundColor = ConsoleColor.Blue            Catch ex As Exception            End Try            Compiler.Report.WriteLine(vbnc.Report.ReportLevels.Debug, "CreateType " & type.FullName & " (" & iCount & " of " & m_TypeDeclarations.Length & " types)")            Try                System.Console.ResetColor()            Catch ex As Exception            End Try#End If#If EXTENDEDDEBUG Then            Try                result = CreateType(type) AndAlso result            Catch ex As Exception                Try                    System.Console.ForegroundColor = ConsoleColor.Red                Catch ex2 As Exception                End Try                Compiler.Report.WriteLine(vbnc.Report.ReportLevels.Debug, ex.Message)                Threading.Thread.Sleep(500)                Try                    System.Console.ResetColor()                Catch ex2 As Exception                End Try                exs.Add(ex)                tps.Add(type)            End Try#Else            result = CreateType(type) AndAlso result#End If        Next#If EXTENDEDDEBUG Then        If exs.Count > 0 Then            Dim msg As String = ""            msg = exs.Count.ToString & " types failed to be created." & VB.vbNewLine            For i As Integer = 0 To exs.Count - 1                msg &= VB.vbTab & tps(i).FullName & ": " & exs(i).Message & VB.vbNewLine            Next            Try                System.Console.ForegroundColor = ConsoleColor.Red            Catch ex2 As Exception            End Try            Compiler.Report.WriteLine(vbnc.Report.ReportLevels.Debug, msg)            Try                System.Console.ResetColor()            Catch ex2 As Exception            End Try            Throw New InternalException(msg)        End If#End If        Return result    End Function    ''' <summary>    ''' Checks whether the specified Type is defined in the current compiling assembly    ''' </summary>    ''' <param name="Type"></param>    ''' <returns></returns>    ''' <remarks></remarks>    Function IsDefinedHere(ByVal Type As Type) As Boolean        Helper.Assert(Type IsNot Nothing)        If TypeOf Type Is TypeBuilder Then Return True        If TypeOf Type Is TypeDescriptor Then Return True        Return Type.Assembly.Equals(Compiler.AssemblyBuilder)    End Function    Function FindType(ByVal FullName As String) As TypeDeclaration        For Each type As TypeDeclaration In Me.Types            If NameResolution.CompareName(type.FullName, FullName) Then Return type        Next        Return Nothing    End Function    Property Name() As String        Get            Return m_Name        End Get        Set(ByVal value As String)            m_Name = value        End Set    End Property    ReadOnly Property Types() As TypeDeclaration()        Get            Return m_TypeDeclarations        End Get    End Property    ReadOnly Property Attributes() As Attributes        Get            Return m_Attributes        End Get    End PropertyEnd Class

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -