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

📄 typedeclaration.vb

📁 大名鼎鼎的mono是.NET平台的跨平台(支持linux
💻 VB
📖 第 1 页 / 共 2 页
字号:
            m_TypeBuilder = value        End Set    End Property    Private ReadOnly Property TypeBuilder2() As System.Reflection.Emit.TypeBuilder Implements IType.TypeBuilder        Get            Return TypeBuilder        End Get    End Property    Public ReadOnly Property TypeDescriptor() As TypeDescriptor Implements IType.TypeDescriptor        Get            Return m_TypeDescriptor        End Get    End Property    ReadOnly Property IsNestedType() As Boolean Implements IType.IsNestedType        Get            Dim result As Boolean            result = DeclaringType IsNot Nothing            Helper.Assert(result = (Me.FindFirstParent(Of IType)() IsNot Nothing))            Return result        End Get    End Property    Public Overridable Function ResolveType() As Boolean Implements IType.ResolveType        Dim result As Boolean = True        Helper.Assert(m_BaseType IsNot Nothing)        Return result    End Function    Public Overrides Function ResolveTypeReferences() As Boolean        Dim result As Boolean = True        result = MyBase.ResolveTypeReferences AndAlso result        If File IsNot Nothing AndAlso File.IsOptionCompareText Then            Dim textAttribute As Attribute            textAttribute = New Attribute(Me, Compiler.TypeCache.MS_VB_CS_OptionTextAttribute)            CustomAttributes.Add(textAttribute)        End If        m_StaticVariables = New Generic.List(Of VariableDeclaration)        For Each method As MethodDeclaration In m_Members.GetSpecificMembers(Of MethodDeclaration)()            If method.Code IsNot Nothing Then method.Code.FindStaticVariables(m_StaticVariables)        Next        For Each prop As PropertyDeclaration In m_Members.GetSpecificMembers(Of PropertyDeclaration)()            If prop.GetDeclaration IsNot Nothing AndAlso prop.GetDeclaration.Code IsNot Nothing Then prop.GetDeclaration.Code.FindStaticVariables(m_StaticVariables)            If prop.SetDeclaration IsNot Nothing AndAlso prop.SetDeclaration.Code IsNot Nothing Then prop.SetDeclaration.Code.FindStaticVariables(m_StaticVariables)        Next        Return result    End Function    Overridable Function DefineType() As Boolean Implements IDefinableType.DefineType        Dim result As Boolean = True        Helper.Assert(m_BaseType IsNot Nothing OrElse Me.TypeDescriptor.IsInterface)        'Helper.Assert(m_Name IsNot Nothing)        'Create the type builder.        Dim Attr As TypeAttributes        Attr = Me.TypeAttributes        If m_BeforeFieldInit Then            Attr = Attr Or Reflection.TypeAttributes.BeforeFieldInit        End If        If IsNestedType Then            Helper.Assert(DeclaringType IsNot Nothing)            Helper.Assert(DeclaringType.TypeBuilder IsNot Nothing)#If EXTENDEDDEBUG Then            Compiler.Report.WriteLine("Defining nested type: " & Name & " with attributes: " & Attr.ToString & " = " & CInt(Attr))#End If            m_TypeBuilder = DeclaringType.TypeBuilder.DefineNestedType(Name, Attr)        Else#If EXTENDEDDEBUG Then            Compiler.Report.WriteLine("Defining type: " & Name & " with attributes: " & Attr.ToString & " = " & CInt(Attr))#End If            m_TypeBuilder = Compiler.ModuleBuilder.DefineType(FullName, Attr)#If DEBUGREFLECTION Then            Helper.DebugReflection_AppendLine(String.Format("{0} = {1}.DefineType(""{2}"", {3})", Helper.GetObjectName(m_TypeBuilder), Helper.GetObjectName(Compiler.ModuleBuilder), FullName, CInt(Attr).ToString))#End If        End If#If ENABLECECIL Then        m_CecilType = New Mono.Cecil.TypeDefinition(Me.Name, Me.Namespace, CType(Attr, Mono.Cecil.TypeAttributes), Nothing)        Compiler.ModuleBuilderCecil.Types.Add(m_CecilType)#End If        Compiler.TypeManager.RegisterReflectionType(m_TypeBuilder, Me.TypeDescriptor)        Helper.Assert(m_TypeBuilder IsNot Nothing)        Return result    End Function    Public Overridable Function DefineTypeHierarchy() As Boolean Implements IDefinableType.DefineTypeHierarchy        Dim result As Boolean = True#If ENABLECECIL Then        If m_BaseType IsNot Nothing Then            m_CecilBaseType = Helper.GetTypeDefinition(Compiler, m_BaseType)        Else            m_CecilBaseType = Nothing        End If        m_CecilType.BaseType = m_CecilBaseType        If IsNestedType Then            DeclaringType.CecilType.NestedTypes.Add(m_CecilType)        End If#End If        If m_TypeBuilder IsNot Nothing Then            m_BaseType = Helper.GetTypeOrTypeBuilder(m_BaseType)#If EXTENDEDDEBUG Then            If Me.BaseType Is Nothing Then                Compiler.Report.WriteLine("Setting parent of " & FullName & " to Nothing")            Else                Compiler.Report.WriteLine("Setting parent of " & FullName & " to " & Me.BaseType.FullName)            End If#End If            m_TypeBuilder.SetParent(m_BaseType)#If DEBUGREFLECTION Then            Helper.DebugReflection_AppendLine(String.Format("{0}.SetParent({1})", Helper.GetObjectName(m_TypeBuilder), Helper.GetObjectName(m_BaseType)))#End If            If m_ImplementedTypes IsNot Nothing Then                For Each Type As Type In m_ImplementedTypes                    Type = Helper.GetTypeOrTypeBuilder(Type)                    Helper.Assert(Type.IsInterface)#If EXTENDEDDEBUG Then                    Compiler.Report.WriteLine("Setting implement," & FullName & " now implements " & Type.FullName)#End If                    m_TypeBuilder.AddInterfaceImplementation(Type)                Next            End If        Else            Helper.Assert(m_EnumBuilder IsNot Nothing)        End If        Return result    End Function    Public Function SetDefaultAttribute(ByVal Name As String) As Boolean        Dim result As Boolean = True        For Each att As Attribute In CustomAttributes            result = att.ResolveCode(ResolveInfo.Default(Compiler)) AndAlso result            If result = False Then Return result            If Helper.CompareType(att.AttributeType, Compiler.TypeCache.System_Reflection_DefaultMemberAttribute) Then                Dim tmpName As String                tmpName = TryCast(att.GetArgument(0), String)                If tmpName IsNot Nothing AndAlso NameResolution.CompareNameOrdinal(Name, tmpName) = False Then                    Compiler.Report.ShowMessage(Messages.VBNC32304, Location, Me.FullName, tmpName, Name)                    Return False                End If                Return True            End If        Next        Helper.NotImplementedYet("Check that the property is indexed.")        Dim attrib As Attribute        attrib = New Attribute(Me, Compiler.TypeCache.System_Reflection_DefaultMemberAttribute, Name)        result = attrib.ResolveCode(ResolveInfo.Default(Compiler)) AndAlso result        CustomAttributes.Add(attrib)        Return result    End Function    Public Overrides Function ResolveCode(ByVal Info As ResolveInfo) As Boolean        Dim result As Boolean = True        Me.CheckCodeNotResolved()        result = MyBase.ResolveCode(Info) AndAlso result        result = m_Members.ResolveCode(Info) AndAlso result        'vbnc.Helper.Assert(result = (Compiler.Report.Errors = 0))        Return result    End Function    Friend Overrides Function GenerateCode(ByVal Info As EmitInfo) As Boolean        Dim result As Boolean = True        For Each var As VariableDeclaration In m_StaticVariables            result = var.DefineStaticMember AndAlso result        Next        result = MyBase.GenerateCode(Info) AndAlso result        Return result    End Function    ''' <summary>    ''' Creates the type if it has not already been created.    ''' </summary>    ''' <returns></returns>    ''' <remarks></remarks>    Public Overridable Function CreateType() As Boolean Implements ICreatableType.CreateType        If m_FinalType IsNot Nothing Then Return True        'HACK: !!!        If TypeOf Me Is ModuleDeclaration Then            If Helper.IsOnMS Then                'This is necessary, otherwise the typebuilder will create a default constructor for the module.                'http://lab.msdn.microsoft.com/productfeedback/viewfeedback.aspx?feedbackid=9bde9cf4-61e3-4b02-9fb5-894359cb7849                GetType(TypeBuilder).GetField("m_constructorCount", BindingFlags.NonPublic Or BindingFlags.Instance).SetValue(m_TypeBuilder, -1)            End If        End If        'HACK!!!#If EXTENDEDDEBUG Then        Report.WriteLine(vbnc.Report.ReportLevels.Debug, "Creating: " & Me.FullName)#End If        If m_TypeBuilder IsNot Nothing Then#If DEBUGREFLECTION Then            Helper.DebugReflection_AppendLine(String.Format("{0}.CreateType ()", Helper.GetObjectName(m_TypeBuilder)))#End If            m_FinalType = m_TypeBuilder.CreateType()        ElseIf m_EnumBuilder IsNot Nothing Then            m_FinalType = m_EnumBuilder.CreateType()        Else            Throw New InternalException(Me)        End If#If EXTENDEDDEBUG Then        Report.WriteLine(vbnc.Report.ReportLevels.Debug, "Created:  " & Me.FullName)#End If        Return True    End Function    ReadOnly Property StaticVariables() As Generic.List(Of VariableDeclaration)        Get            Return m_StaticVariables        End Get    End Property    MustOverride ReadOnly Property TypeAttributes() As System.Reflection.TypeAttributes Implements IType.TypeAttributes    ReadOnly Property IsInterface() As Boolean        Get            Return TypeOf Me Is InterfaceDeclaration        End Get    End Property    ReadOnly Property IsClass() As Boolean        Get            Return TypeOf Me Is ClassDeclaration        End Get    End Property    ReadOnly Property IsDelegate() As Boolean        Get            Return TypeOf Me Is DelegateDeclaration        End Get    End Property    ReadOnly Property IsValueType() As Boolean        Get            Return TypeOf Me Is StructureDeclaration        End Get    End Property    ReadOnly Property IsEnum() As Boolean        Get            Return TypeOf Me Is EnumDeclaration        End Get    End Property    ReadOnly Property IsModule() As Boolean        Get            Return TypeOf Me Is ModuleDeclaration        End Get    End Property    ReadOnly Property HasInstanceConstructors() As Boolean        Get            Dim ctors As Generic.List(Of ConstructorDeclaration)            ctors = Me.Members.GetSpecificMembers(Of ConstructorDeclaration)()            For Each item As ConstructorDeclaration In ctors                If item.IsShared = False Then Return True            Next            Return False        End Get    End Property    ReadOnly Property HasSharedConstantFields() As Boolean        Get            Dim ctors As Generic.List(Of ConstantDeclaration)            ctors = Me.Members.GetSpecificMembers(Of ConstantDeclaration)()            Return ctors.Count > 0        End Get    End Property    ReadOnly Property HasSharedFieldsWithInitializers() As Boolean        Get            Dim ctors As Generic.List(Of VariableDeclaration)            ctors = Me.Members.GetSpecificMembers(Of VariableDeclaration)()            For Each item As VariableDeclaration In ctors                If item.IsShared AndAlso item.HasInitializer Then Return True            Next            For Each item As VariableDeclaration In m_StaticVariables                If item.DeclaringMethod.IsShared AndAlso item.HasInitializer Then Return True            Next            Return False        End Get    End PropertyEnd Class

⌨️ 快捷键说明

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