/
Form1.vb
143 lines (130 loc) · 4.88 KB
/
Form1.vb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
Imports Microsoft.VisualBasic
Imports System
Imports System.Drawing
Imports System.Collections
Imports System.ComponentModel
Imports System.Windows.Forms
Imports System.Data
Imports System.Configuration
Imports DevExpress.Xpo
Imports DevExpress.Xpo.Metadata
Imports DevExpress.Xpo.Metadata.Helpers
Imports DevExpress.Xpo.DB
Namespace ObjectProperties
''' <summary>
''' Summary description for Form1.
''' </summary>
Public Class Form1
Inherits System.Windows.Forms.Form
Private WithEvents comboBox1 As System.Windows.Forms.ComboBox
Private listBox1 As System.Windows.Forms.ListBox
''' <summary>
''' Required designer variable.
''' </summary>
Private components As System.ComponentModel.Container = Nothing
Public Sub New()
InitializeComponent()
End Sub
''' <summary>
''' Clean up any resources being used.
''' </summary>
Protected Overrides Overloads Sub Dispose(ByVal disposing As Boolean)
If disposing Then
If components IsNot Nothing Then
components.Dispose()
End If
End If
MyBase.Dispose(disposing)
End Sub
#Region "Windows Form Designer generated code"
''' <summary>
''' Required method for Designer support - do not modify
''' the contents of this method with the code editor.
''' </summary>
Private Sub InitializeComponent()
Me.comboBox1 = New System.Windows.Forms.ComboBox()
Me.listBox1 = New System.Windows.Forms.ListBox()
Me.SuspendLayout()
'
' comboBox1
'
Me.comboBox1.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList
Me.comboBox1.Location = New System.Drawing.Point(24, 8)
Me.comboBox1.Name = "comboBox1"
Me.comboBox1.Size = New System.Drawing.Size(272, 24)
Me.comboBox1.TabIndex = 0
' Me.comboBox1.SelectedValueChanged += New System.EventHandler(Me.comboBox1_SelectedValueChanged);
'
' listBox1
'
Me.listBox1.ItemHeight = 16
Me.listBox1.Location = New System.Drawing.Point(24, 64)
Me.listBox1.Name = "listBox1"
Me.listBox1.Size = New System.Drawing.Size(272, 260)
Me.listBox1.TabIndex = 1
'
' Form1
'
Me.AutoScaleBaseSize = New System.Drawing.Size(6, 15)
Me.ClientSize = New System.Drawing.Size(312, 341)
Me.Controls.AddRange(New System.Windows.Forms.Control() { Me.listBox1, Me.comboBox1})
Me.Name = "Form1"
Me.Text = "Form1"
' Me.Load += New System.EventHandler(Me.Form1_Load);
Me.ResumeLayout(False)
End Sub
#End Region
''' <summary>
''' The main entry point for the application.
''' </summary>
<STAThread> _
Shared Sub Main()
Dim conn As String = MSSqlConnectionProvider.GetConnectionString("(local)", "Northwind")
XpoDefault.DataLayer = XpoDefault.GetDataLayer(conn, AutoCreateOption.SchemaAlreadyExists)
XpoDefault.Session.Dictionary.CollectClassInfos(GetType(Customer).Assembly)
Application.Run(New Form1())
End Sub
Private Sub Form1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.Load
For Each info As XPClassInfo In XpoDefault.Session.Dictionary.Classes
If info.IsPersistent AndAlso info.IsVisibleInDesignTime Then
comboBox1.Items.Add(info)
End If
Next info
End Sub
Private Function GetObjectProperties(ByVal classInfo As XPClassInfo) As String()
If classInfo IsNot Nothing Then
Return GetObjectProperties(classInfo, New ArrayList())
End If
Return New String() { }
End Function
Private Function GetObjectProperties(ByVal xpoInfo As XPClassInfo, ByVal processed As ArrayList) As String()
If processed.Contains(xpoInfo) Then
Return New String() {}
End If
processed.Add(xpoInfo)
Dim result As New ArrayList()
For Each m As XPMemberInfo In xpoInfo.PersistentProperties
If Not (TypeOf m Is ServiceField) AndAlso m.IsPersistent Then
result.Add(m.Name)
If m.ReferenceType IsNot Nothing Then
Dim childProps() As String = GetObjectProperties(m.ReferenceType, processed)
For Each child As String In childProps
result.Add(String.Format("{0}.{1}", m.Name, child))
Next child
End If
End If
Next m
For Each m As XPMemberInfo In xpoInfo.CollectionProperties
Dim childProps() As String = GetObjectProperties(m.CollectionElementType, processed)
For Each child As String In childProps
result.Add(String.Format("{0}.{1}", m.Name, child))
Next child
Next m
Return TryCast(result.ToArray(GetType(String)), String())
End Function
Private Sub comboBox1_SelectedValueChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles comboBox1.SelectedValueChanged
listBox1.Items.Clear()
listBox1.Items.AddRange(GetObjectProperties(CType(comboBox1.SelectedItem, XPClassInfo)))
End Sub
End Class
End Namespace