📄 genericmethoddescriptor.vb
字号:
' ' Visual Basic.Net Compiler' Copyright (C) 2004 - 2007 Rolf Bjarne Kvinge, RKvinge@novell.com' ' This library is free software; you can redistribute it and/or' modify it under the terms of the GNU Lesser General Public' License as published by the Free Software Foundation; either' version 2.1 of the License, or (at your option) any later version.' ' This library is distributed in the hope that it will be useful,' but WITHOUT ANY WARRANTY; without even the implied warranty of' MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU' Lesser General Public License for more details.' ' You should have received a copy of the GNU Lesser General Public' License along with this library; if not, write to the Free Software' Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA' #If DEBUG Then#Const DEBUGMETHODACCESS = 0#Const EXTENDEDDEBUG = 0#End IfPublic Class GenericMethodDescriptor Inherits MethodDescriptor Private m_ClosedType As Type Private m_OpenMethodDescriptor As MethodDescriptor Private m_OpenMethod As MethodInfo Private m_ClosedMethodDescriptor As MethodDescriptor Private m_ClosedMethod As MethodInfo ''' <summary> ''' The open type parameters for this method. ''' </summary> ''' <remarks></remarks> Private m_TypeParameters As Type() ''' <summary> ''' The types to close this method with. ''' </summary> ''' <remarks></remarks> Private m_TypeArguments As Type() ''' <summary> ''' Creates a closed method on a generic type. ''' </summary> ''' <param name="Parent"></param> ''' <param name="OpenMethod"></param> ''' <param name="TypeParameters"></param> ''' <param name="TypeArguments"></param> ''' <param name="ClosedType"></param> ''' <remarks></remarks> Sub New(ByVal Parent As ParsedObject, ByVal OpenMethod As MethodInfo, ByVal TypeParameters As Type(), ByVal TypeArguments() As Type, ByVal ClosedType As Type) MyBase.New(Parent) m_ClosedType = ClosedType m_OpenMethod = OpenMethod m_OpenMethodDescriptor = TryCast(m_OpenMethod, MethodDescriptor) m_TypeParameters = TypeParameters m_TypeArguments = TypeArguments Helper.Assert(m_TypeParameters.Length = m_TypeArguments.Length)#If DEBUG Then Try Dim tmp As Type() = Nothing 'Dim t As Type = Me.ReturnType If ClosedType.IsGenericTypeDefinition Then tmp = ClosedType.GetGenericArguments ElseIf ClosedType.IsGenericType Then tmp = ClosedType.GetGenericTypeDefinition.GetGenericArguments End If If tmp IsNot Nothing Then Helper.Assert(m_TypeParameters.Length = tmp.Length) For i As Integer = 0 To tmp.Length - 1 Helper.Assert(tmp(i).Name = m_TypeParameters(i).Name) Next End If Catch ex As Exception Helper.Assert(False, ex.Message) End Try#End If End Sub ''' <summary> ''' Creates a closed method of an open generic method. ''' </summary> ''' <param name="Parent"></param> ''' <param name="OpenMethod"></param> ''' <param name="TypeParameters"></param> ''' <param name="TypeArguments"></param> ''' <remarks></remarks> Sub New(ByVal Parent As ParsedObject, ByVal OpenMethod As MethodInfo, ByVal TypeParameters As Type(), ByVal TypeArguments() As Type) MyBase.New(Parent) m_OpenMethod = OpenMethod m_OpenMethodDescriptor = TryCast(m_OpenMethod, MethodDescriptor) m_TypeParameters = TypeParameters m_TypeArguments = TypeArguments Helper.Assert(m_TypeParameters.Length = m_TypeArguments.Length) End Sub Public Overrides ReadOnly Property IsGenericMethod() As Boolean Get Dim result As Boolean result = m_OpenMethod.IsGenericMethod DumpMethodInfo(result) Return result End Get End Property Public Overrides Function GetCustomAttributes(ByVal inherit As Boolean) As Object() Return MyBase.GetCustomAttributes(inherit) End Function Public Overrides Function GetCustomAttributes(ByVal attributeType As System.Type, ByVal inherit As Boolean) As Object() Dim result As Object() If m_OpenMethodDescriptor IsNot Nothing Then result = m_OpenMethodDescriptor.GetCustomAttributes(attributeType, inherit) ElseIf m_ClosedMethodDescriptor IsNot Nothing Then result = Helper.FilterCustomAttributes(attributeType, inherit, m_ClosedMethodDescriptor.Declaration) Else Helper.NotImplemented() result = Nothing End If DumpMethodInfo(result) Return result End Function Public Overrides Function GetGenericArguments() As System.Type() Dim result As Type() If m_OpenMethod.IsGenericMethodDefinition Then If TypeOf m_OpenMethod Is MethodBuilder = False Then result = m_OpenMethod.GetGenericArguments Else Helper.NotImplemented() result = Nothing End If Else result = Type.EmptyTypes End If DumpMethodInfo(result) Return result End Function Public Overrides ReadOnly Property IsShared() As Boolean Get Return m_OpenMethod.IsStatic End Get End Property Public Overrides ReadOnly Property Attributes() As System.Reflection.MethodAttributes Get Dim result As MethodAttributes result = m_OpenMethod.Attributes DumpMethodInfo(result) Return result End Get End Property Public Overrides ReadOnly Property Name() As String Get Dim result As String result = m_OpenMethod.Name DumpMethodInfo(result) Return result End Get End Property Public Overrides ReadOnly Property ReturnType() As System.Type Get Static result As Type If result Is Nothing Then If m_OpenMethodDescriptor IsNot Nothing Then result = m_OpenMethodDescriptor.ReturnType Else result = m_OpenMethod.ReturnType End If result = Helper.ApplyTypeArguments(Me.Parent, result, m_TypeParameters, m_TypeArguments) End If DumpMethodInfo(result) Return result End Get End Property Public Overrides ReadOnly Property DeclaringType() As System.Type Get Dim result As Type If m_ClosedType Is Nothing Then result = m_OpenMethod.DeclaringType
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -