📄 typedescriptor.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 DEBUGTYPEACCESS = 0#End If''' <summary>''' Represents a type, either in the parse tree or of the Type type.''' </summary>''' <remarks></remarks>Public Class TypeDescriptor Inherits Type Implements IMemberDescriptor Private m_Declaration As TypeDeclaration Private m_Parent As ParsedObject Private m_AllMembers As Generic.List(Of MemberInfo) Private m_AllDeclaredMembers As Generic.List(Of MemberInfo) Private m_ObjectID As Integer = BaseObject.NewID#If DEBUG Then Private m_AllDescriptor As New Generic.List(Of TypeDescriptor) Private m_AllTypeIDs As New Generic.List(Of Integer) Private m_Hashed As New Generic.Dictionary(Of Integer, TypeDescriptor)#End If ReadOnly Property IsShared() As Boolean Implements IMemberDescriptor.IsShared Get Return m_Declaration.IsShared End Get End Property ReadOnly Property Parent() As ParsedObject Get Return m_Parent End Get End Property ReadOnly Property Compiler() As Compiler Get Return m_Parent.Compiler End Get End Property Public Overrides Function ToString() As String Return Me.FullName End Function ReadOnly Property Declaration() As TypeDeclaration Get Return m_Declaration End Get End Property Private ReadOnly Property MemberDeclaration() As IMember Implements IMemberDescriptor.Declaration Get Return m_Declaration End Get End Property Shared Function CreateList(ByVal types As System.Collections.IEnumerable) As TypeList Dim result As New TypeList For Each t As IType In types result.Add(t.TypeDescriptor) Next Return result End Function Sub New(ByVal Type As TypeDeclaration) If Type Is Nothing Then Throw New ArgumentNullException("IType") m_Declaration = Type m_Parent = m_Declaration#If DEBUG Then VerifyUnique(Type)#End If End Sub Protected Sub New(ByVal Parent As ParsedObject) Helper.Assert(Parent IsNot Nothing) m_Parent = Parent m_Declaration = TryCast(Parent, TypeDeclaration) End Sub#If DEBUG Then Sub VerifyUnique(ByVal obj As IBaseObject) Dim id As Integer = obj.ObjectID Helper.Assert(m_AllDescriptor.Contains(Me) = False) Helper.Assert(m_AllTypeIDs.Contains(id) = False) m_AllDescriptor.Add(Me) m_AllTypeIDs.Add(id) m_Hashed.Add(id, Me) 'Diagnostics.Debug.WriteLine("Created td: " & id.ToString) End Sub#End If ''' <summary> ''' Gets the Reflection.Emit created type for this descriptor. ''' It is a TypeBuilder. ''' </summary> ''' <value></value> ''' <returns></returns> ''' <remarks></remarks> Overridable ReadOnly Property TypeInReflection() As Type Get Dim result As Type = Nothing Helper.Assert(m_Declaration IsNot Nothing) result = m_Declaration.TypeBuilder If result Is Nothing Then result = m_Declaration.EnumBuilder End If Return result End Get End Property#Region "Inherited members from Type" <Diagnostics.Conditional("DEBUGTYPEACCESS")> _ Protected Sub DumpMethodInfo(Optional ByVal ReturnValue As Object = Nothing)#If DEBUGTYPEACCESS Then Static recursive As Boolean If recursive Then Return recursive = True Dim m As New Diagnostics.StackFrame(1) Dim str As String Dim name As String = Me.FullName If name Is Nothing Then name = "(TypeParameter: " & Me.Name & ")" str = " Called: (" & name & "): Type." If ReturnValue IsNot Nothing Then Compiler.Report.WriteLine(Report.ReportLevels.Debug, str & m.GetMethod.Name & " with return value: " & ReturnValue.ToString) Else Compiler.Report.WriteLine(Report.ReportLevels.Debug, str & m.GetMethod.Name) End If recursive = False#End If End Sub Public Overrides ReadOnly Property GenericParameterAttributes() As System.Reflection.GenericParameterAttributes Get Dim result As GenericParameterAttributes Helper.NotImplemented() DumpMethodInfo(result) Return result End Get End Property Public Overrides ReadOnly Property GenericParameterPosition() As Integer Get Dim result As Integer Helper.NotImplemented() DumpMethodInfo(result) Return result End Get End Property ''' <summary> ''' A hack to prevent the debugger to crash when inspecthing type descriptors. ''' </summary> ''' <value></value> ''' <returns></returns> ''' <remarks></remarks> Shadows ReadOnly Property IsVisible() As Boolean Get Return True End Get End Property Public Overrides ReadOnly Property IsGenericParameter() As Boolean Get Dim result As Boolean result = False DumpMethodInfo(result) Return result End Get End Property Public Overrides ReadOnly Property IsGenericType() As Boolean Get Dim result As Boolean Helper.Assert(m_Declaration IsNot Nothing) Dim cdecl As IConstructable = TryCast(m_Declaration, IConstructable) If cdecl IsNot Nothing Then If cdecl.TypeParameters IsNot Nothing Then If cdecl.TypeParameters.Parameters IsNot Nothing Then result = cdecl.TypeParameters.Parameters.Length > 0 Else result = False End If ElseIf Me.IsNested AndAlso Me.DeclaringType.IsGenericType Then result = True Else result = False End If Else result = False End If DumpMethodInfo(result) Return result End Get End Property Public Overrides ReadOnly Property IsGenericTypeDefinition() As Boolean Get Dim result As Boolean Helper.Assert(m_Declaration IsNot Nothing) Dim cdecl As IConstructable = TryCast(m_Declaration, IConstructable) If cdecl IsNot Nothing Then result = cdecl.TypeParameters IsNot Nothing AndAlso cdecl.TypeParameters.Parameters.Length > 0 Else result = False End If Helper.Assert(m_Declaration.TypeBuilder Is Nothing OrElse m_Declaration.TypeBuilder.IsGenericTypeDefinition = result) DumpMethodInfo(result) Return result End Get End Property Public Overrides ReadOnly Property DeclaringType() As System.Type Get Dim result As Type If m_Declaration.IsNestedType Then result = m_Declaration.FindFirstParent(Of IType).TypeDescriptor Else result = Nothing End If DumpMethodInfo(result) Return result End Get End Property Public Overrides ReadOnly Property FullName() As String Get Dim result As String Helper.Assert(m_Declaration IsNot Nothing) result = m_Declaration.FullName DumpMethodInfo(result) Helper.Assert(result.IndexOf("\"c) = -1) Return result End Get End Property Overrides ReadOnly Property Name() As String Get Dim result As String = "" Helper.Assert(m_Declaration IsNot Nothing) result = m_Declaration.Name DumpMethodInfo(result) Return result End Get End Property Public Overrides ReadOnly Property Assembly() As System.Reflection.Assembly Get Dim result As System.Reflection.Assembly result = m_Parent.Compiler.AssemblyBuilder DumpMethodInfo(result) Return result End Get End Property Public Overrides ReadOnly Property AssemblyQualifiedName() As String Get DumpMethodInfo() Helper.NotImplemented() : Return Nothing End Get End Property Public Overrides ReadOnly Property BaseType() As System.Type Get Dim result As Type = Nothing Helper.Assert(m_Declaration IsNot Nothing) result = m_Declaration.BaseType DumpMethodInfo(result) Return result End Get End Property Protected Overrides Function GetAttributeFlagsImpl() As System.Reflection.TypeAttributes Dim result As TypeAttributes Helper.Assert(m_Declaration IsNot Nothing) result = TypeResolution.getTypeAttributeScopeFromScope(m_Declaration.Modifiers, m_Declaration.IsNestedType) If TypeOf m_Declaration Is ClassDeclaration Then result = result Or TypeAttributes.Class ElseIf TypeOf m_Declaration Is InterfaceDeclaration Then result = result Or TypeAttributes.Interface Or TypeAttributes.Abstract End If 'If Modifiers.IsNothing(m_Declaration.Modifiers) = False Then If m_Declaration.Modifiers.Is(ModifierMasks.NotInheritable) Then result = result Or TypeAttributes.Sealed End If If m_Declaration.Modifiers.Is(ModifierMasks.MustInherit) Then result = result Or TypeAttributes.Abstract End If 'End If DumpMethodInfo(result) Return result End Function Protected Overrides Function GetConstructorImpl(ByVal bindingAttr As System.Reflection.BindingFlags, ByVal binder As System.Reflection.Binder, ByVal callConvention As System.Reflection.CallingConventions, ByVal types() As System.Type, ByVal modifiers() As System.Reflection.ParameterModifier) As System.Reflection.ConstructorInfo Dim result As ConstructorInfo = Nothing Dim tmp As MemberInfo() tmp = GetMembers(bindingAttr) For i As Integer = 0 To tmp.Length - 1 Dim member As MemberInfo = tmp(i) If member.MemberType = MemberTypes.Constructor Then If Helper.CompareTypes(Helper.GetTypes(Helper.GetParameters(Compiler, member)), types) Then Helper.Assert(result Is Nothing) result = DirectCast(member, ConstructorInfo) End If End If Next DumpMethodInfo(result) Return result End Function Public Overloads Overrides Function GetConstructors(ByVal bindingAttr As System.Reflection.BindingFlags) As System.Reflection.ConstructorInfo() Dim result As Generic.List(Of ConstructorInfo) result = GetMembers(Of ConstructorInfo)(MemberTypes.Constructor, bindingAttr) DumpMethodInfo(result.ToArray) Return result.ToArray End Function Public Overloads Overrides Function GetCustomAttributes(ByVal inherit As Boolean) As Object() Dim result As Object() = Nothing DumpMethodInfo(result) Helper.NotImplemented() Return result End Function Public Overloads Overrides Function GetCustomAttributes(ByVal attributeType As System.Type, ByVal inherit As Boolean) As Object() Dim result As Object() result = Helper.FilterCustomAttributes(attributeType, inherit, m_Declaration) DumpMethodInfo(result) Return result End Function Public Overrides Function GetElementType() As System.Type Dim result As Type If Me.IsEnum Then result = DirectCast(m_Declaration, EnumDeclaration).EnumConstantType Else result = Nothing End If DumpMethodInfo(result) Return result End Function Public Overloads Overrides Function GetEvent(ByVal name As String, ByVal bindingAttr As System.Reflection.BindingFlags) As System.Reflection.EventInfo DumpMethodInfo() Helper.NotImplemented() : Return Nothing End Function Public Overloads Overrides Function GetEvents(ByVal bindingAttr As System.Reflection.BindingFlags) As System.Reflection.EventInfo() DumpMethodInfo() Helper.NotImplemented() : Return Nothing End Function Public Overloads Overrides Function GetField(ByVal name As String, ByVal bindingAttr As System.Reflection.BindingFlags) As System.Reflection.FieldInfo Dim result As FieldInfo Dim members As Generic.List(Of INameable) members = m_Declaration.Members.Index.Item(name)
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -