【问题标题】:Retrieving information out of a Class module collection in VB.Net从 VB.Net 中的类模块集合中检索信息
【发布时间】:2016-03-17 05:01:15
【问题描述】:

目前我遇到了一个问题/正在努力了解如何从类模块中提取信息。 我的理解是,如果类模块是 Excel 表,则实例将是一行,公共属性将是我在查看链接(Retrieving information from a Class module VB.Net)之前发布此问题的列,这是我使用代码的地方

在我的类模块中

Public Class tDCVillains 
    Public Property Gothem As Integer
    Public Property metropolis as Integer
End Class

将信息插入类模块

Sub GrabAccessInfo()
  Dim DCVillains As New tDCVillains
  Dim VillainsCollection As New Collection
  DCVillains.Gothem = rst("Gothem").Value
  DCVillains.metropolis = rst("metropolis").Value
  VillainsCollection.Add(DCVillains)
  rst.MoveNext()
End Sub

从类模块中检索信息

Sub RackSlotAccess(DCVillains As tDCVillains)
    For Each tDCVillains As System.Reflection.PropertyInfo In tDCVillains ' its not liking tDCVillains  
        Dim ObjGothem = DCVillains.Gothem
        Dim Objmetropolis = DCVillains.metropolis
        If ObjGothem >= 1 Then 
              InsertGothemVillains(ObjGothem, 32, "I", Slot, Rack)
        End If
        If Objmetropolis >= 1 Then 
              InsertmetropolisVillains(Objmetropolis, 16, "I", Slot, Rack)
        End If
    Next
End Sub

它是代码不喜欢的每个语句,但我不知道为什么?

【问题讨论】:

    标签: vb.net excel class class-method class-variables


    【解决方案1】:

    您似乎想循环tDCVillains 类型的属性。你可以使用Type.GetProperties:

    Sub RackSlotAccess(DCVillains As tDCVillains)
        Dim type = GetType(tDCVillains)
        For Each tDCVillains As System.Reflection.PropertyInfo In type.GetProperties()  
            Dim ObjGothem = DCVillains.Gothem
            Dim Objmetropolis = DCVillains.metropolis
            If ObjGothem >= 1 Then
                InsertGothemVillains(ObjGothem, 32, "I", Slot, Rack)
            End If
            If Objmetropolis >= 1 Then
                InsertmetropolisVillains(Objmetropolis, 16, "I", Slot, Rack)
            End If
        Next
    End Sub
    

    【讨论】:

    • VB.Net 脚本不喜欢 GetProperties
    • @AlexGale:你用过GetType(tDCVillains).Getproperties()?是 VB.NET 还是 VB-Script?
    • VB.Net 脚本不喜欢 GetProperties() VB.Net 中的帮助说:`Function Type.Getproperty(名称为字符串,blindingAttr 为反射.BindingFlags,活页夹为反射.Binder, ReturnTyoe as type(), modifier As Reflection.ParameterModifier()) as Reflection.PropertyInfo(+6 重载)
    • @AlexGale:如果我测试代码,除了缺少的InsertmetropolisVillains 方法之外,我没有得到任何编译器错误。您使用的是哪个版本的 .NET? Type.Getproperties 从 .NET 2.0 开始工作
    • @AlexGale:我没用过GetProperty,但GetProperties。你想循环所有属性,你不需要一个属性,是吗?
    猜你喜欢
    • 1970-01-01
    • 2011-06-01
    • 1970-01-01
    • 2021-06-28
    • 2013-10-23
    • 2014-07-02
    • 1970-01-01
    • 1970-01-01
    • 2014-02-09
    相关资源
    最近更新 更多