📄 methodgroupclassification.vb
字号:
''' </summary> ''' <value></value> ''' <returns></returns> ''' <remarks></remarks> ReadOnly Property ResolvedMethod() As MethodBase Get If SuccessfullyResolved = False Then Throw New InternalException(Me) If m_Group.Count = 0 Then Return Nothing Return DirectCast(m_Group(0), MethodBase) End Get End Property ReadOnly Property Resolver() As MethodResolver Get Return m_Resolver End Get End Property ''' <summary> ''' Returns true if the method group has successfully been resolved. ''' </summary> ''' <value></value> ''' <returns></returns> ''' <remarks></remarks> ReadOnly Property SuccessfullyResolved() As Boolean Get Return m_Resolved AndAlso (m_Group.Count = 1 OrElse m_Resolver.IsLateBound) End Get End Property Private Sub SetMethods(ByVal lst As Generic.List(Of MemberInfo)) m_Group = New Generic.List(Of MemberInfo) For i As Integer = 0 To lst.Count - 1 Dim member As MemberInfo = lst(i) Dim method As MethodBase method = TryCast(member, MethodBase) Helper.Assert(method IsNot Nothing) m_Group.Add(method) Next#If DEBUG Then m_OriginalGroup = New Generic.List(Of MemberInfo)(m_Group)#End If End Sub Private Sub SetMethods(ByVal lst As Generic.List(Of MethodBase)) m_Group = New Generic.List(Of MemberInfo) For i As Integer = 0 To lst.Count - 1 Dim method As MethodBase = lst(i) m_Group.Add(method) Next#If DEBUG Then m_OriginalGroup = New Generic.List(Of MemberInfo)(lst.ToArray)#End If End Sub ''' <summary> ''' The name of the method. (Any method actually, since they should all have the same name). ''' </summary> ''' <value></value> ''' <returns></returns> ''' <remarks></remarks> ReadOnly Property MethodName() As String Get For i As Integer = 0 To m_Group.Count - 1 If m_Group(i) IsNot Nothing Then Return m_Group(i).Name End If Next Throw New InternalException(Me) End Get End Property ''' <summary> ''' The group of methods. ''' </summary> ''' <value></value> ''' <returns></returns> ''' <remarks></remarks> Property [Group]() As Generic.List(Of MemberInfo) Get Return m_Group End Get Set(ByVal value As Generic.List(Of MemberInfo)) m_Group = value End Set End Property Shared Function ResolveInterfaceGroup(ByVal grp As Generic.List(Of MemberInfo), ByVal codedMember As IMember) As MemberInfo Helper.Assert(codedMember IsNot Nothing) Dim methodtypes() As Type Dim grptypes() As Type Dim result As MemberInfo = Nothing Select Case codedMember.MemberDescriptor.MemberType Case MemberTypes.Method Dim method As IMethod = TryCast(codedMember, IMethod) methodtypes = method.Signature.Parameters.ToTypeArray Case MemberTypes.Property Dim prop As PropertyDeclaration = TryCast(codedMember, PropertyDeclaration) methodtypes = prop.Signature.Parameters.ToTypeArray Case MemberTypes.Event methodtypes = Type.EmptyTypes Case Else methodtypes = Nothing Helper.NotImplemented() End Select For Each member As MemberInfo In grp Select Case member.MemberType Case MemberTypes.Method grptypes = Helper.GetParameterTypes(codedMember.Compiler, DirectCast(member, MethodInfo)) Case MemberTypes.Property grptypes = Helper.GetParameterTypes(Helper.GetParameters(codedMember.Compiler, DirectCast(member, PropertyInfo))) Case MemberTypes.Event grptypes = Type.EmptyTypes Case Else Throw New InternalException(codedMember) End Select If Helper.CompareTypes(methodtypes, grptypes) Then Helper.Assert(result Is Nothing) result = member#If Not DEBUG Then Exit For#End If End If Next Return result End Function ReadOnly Property IsLateBound() As Boolean Get Return m_Resolver IsNot Nothing AndAlso m_Resolved AndAlso m_Resolver.IsLateBound End Get End Property ''' <summary> ''' Resolve this group with the specified parameters. ''' </summary> ''' <param name="SourceParameters"></param> ''' <remarks></remarks> Function ResolveGroup(ByVal SourceParameters As ArgumentList, ByRef FinalSourceArguments As Generic.List(Of Argument), Optional ByVal TypeArguments As TypeArgumentList = Nothing, Optional ByVal ShowErrors As Boolean = False) As Boolean Dim result As Boolean = True If SourceParameters Is Nothing Then Throw New InternalException("SourceParameters is nothing.") If Resolved Then Compiler.Report.WriteLine(vbnc.Report.ReportLevels.Debug, "Method group is beeing resolved more than once.") End If If m_Group.Count <= 0 Then Throw New InternalException("Nothing to resolve...") Dim resolvedGroup As New Generic.List(Of MemberInfo) If m_Resolver Is Nothing Then m_Resolver = New MethodResolver(Parent) m_Resolver.ShowErrors = ShowErrors m_Resolver.Init(m_Group, SourceParameters, TypeArguments) result = m_Resolver.Resolve AndAlso result If result Then If m_Resolver.IsLateBound = False Then FinalSourceArguments = m_Resolver.ResolvedCandidate.ExactArguments resolvedGroup.Add(m_Resolver.ResolvedMember) End If End If 'result = Helper.ResolveGroup(Me.Parent, m_Group, resolvedGroup, SourceParameters, TypeArguments, FinalSourceArguments, ShowErrors) AndAlso result If result Then m_Group = resolvedGroup m_Resolved = True If IsLateBound = False AndAlso ResolvedMethod.IsStatic Then 'Helper.StopIfDebugging(m_InstanceExpression IsNot Nothing AndAlso TypeOf m_InstanceExpression Is MeExpression = False) m_InstanceExpression = Nothing End If#If EXTENDEDDEBUG Then Else 'Don't stop here since method resolution might fail correctly. Compiler.Report.WriteLine("") Compiler.Report.WriteLine(".......Method resolution failed, showing log.......") Dim tmp As Boolean = Helper.LOGMETHODRESOLUTION Helper.LOGMETHODRESOLUTION = True resolvedGroup.Clear() result = Helper.ResolveGroup(Me.Parent, m_Group, resolvedGroup, SourceParameters, TypeArguments, FinalSourceArguments) AndAlso result Helper.LOGMETHODRESOLUTION = tmp Compiler.Report.WriteLine("...................................................")#End If End If Return result End Function ''' <summary> ''' Removes methods that are nothing from the group ''' </summary> ''' <remarks></remarks> Private Sub ShrinkGroup() m_Group.RemoveAll(New Predicate(Of MemberInfo)(AddressOf Helper.IsNothing(Of MemberInfo))) End Sub Function IsAccessible(ByVal Caller As TypeDeclaration, ByVal Method As MethodBase) As Boolean Return Helper.IsAccessible(Compiler, Caller, Method) End Function Sub New(ByVal Parent As ParsedObject, ByVal InstanceExpression As Expression, ByVal Method As MethodDeclaration) MyBase.New(Classifications.MethodGroup, Parent) m_Group = New Generic.List(Of MemberInfo) m_Group.Add(Method.MethodDescriptor) m_Resolved = True m_InstanceExpression = InstanceExpression End Sub Private Sub New(ByVal Parent As ParsedObject, ByVal InstanceExpression As Expression, ByVal Parameters() As Expression) MyBase.new(Classifications.MethodGroup, Parent) m_InstanceExpression = InstanceExpression m_CallingType = Parent.FindFirstParent(Of TypeDeclaration)() m_Parameters = Parameters 'Helper.Assert(m_CallingType IsNot Nothing) Helper.Assert(m_InstanceExpression Is Nothing OrElse m_InstanceExpression.IsResolved) End Sub Sub New(ByVal Parent As ParsedObject, ByVal InstanceExpression As Expression, ByVal Parameters() As Expression, ByVal ParamArray Methods As MemberInfo()) Me.New(Parent, InstanceExpression, Parameters) SetMethods(New Generic.List(Of MemberInfo)(Methods)) Helper.Assert(Methods.Length > 0) Helper.Assert(m_InstanceExpression Is Nothing OrElse m_InstanceExpression.IsResolved) End Sub Sub New(ByVal Parent As ParsedObject, ByVal InstanceExpression As Expression, ByVal Parameters() As Expression, ByVal Methods As Generic.List(Of MemberInfo)) Me.new(Parent, InstanceExpression, Parameters) SetMethods(Methods) Helper.Assert(Methods.Count > 0) Helper.Assert(m_InstanceExpression Is Nothing OrElse m_InstanceExpression.IsResolved) End Sub Shadows ReadOnly Property Parent() As ParsedObject Get Return DirectCast(MyBase.Parent, ParsedObject) End Get End PropertyEnd Class
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -