I can easily list all controls in a Form, after creating an instance of it.
Is there any mechanism to list all declared variables or such objects?
Perhaps I shall call it declarations. Only top-level declarations are enough.
Let's assume we have MyForm
Form with such top-level declarations:
Dim Town as String
Dim ZIP as String
Dim StreetName as String
Dim StreetNo as String
Public dtCountries as DataTable
Public LstCities as List(Of String)
...
Pseudo-code example:
Dim MyForm as New MyForm ' create instance of the form
Dim dtVariables as New Datatable ' create a datatable to store found objects
dtVariables.Columns.Add("ID", GetTy(Int32))
dtVariables.Columns.Add("VariableName", GetTy(String))
dtVariables.Columns.Add("VariableType", GetTy(String))
For Each Varbl In MyForm.***variables*** ' <<< (how) to read all variables
Dim nr as Datarow = dtVariables.NewRow
nr("ID") = dtVariables.Rows.Count + 1
nr("VariableName") = Varbl.Name
nr("VariableType") = Varbl.GetType.ToString.Replace("System.Windows.Forms.", "")
dtVariables.Rows.Add(nr) ' add found object/variable to our datatable
Next
The result I am looking for is something like:
1 Town String
2 ZIP String
3 StreetName String
4 StreetNo Int32
5 dtCountries DataTable
6 LstCities List(Of String)
... ... ...
I know that I can read MyForm.designer.vb
file and look there for declarations.
This question is about getting it from an object model of a Form / instance of a Form.
Aucun commentaire:
Enregistrer un commentaire