-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathObjectInfo.cs
194 lines (180 loc) · 4.46 KB
/
ObjectInfo.cs
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
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
using System;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using System.Text;
namespace Havit.Business;
/// <summary>
/// Reprezentuje informace o objektu (třídě).
/// </summary>
public class ObjectInfo
{
/// <summary>
/// Indikuje, zda je objekt určen jen ke čtení.
/// </summary>
public bool ReadOnly
{
get
{
CheckInitialization();
return readOnly;
}
}
private bool readOnly;
/// <summary>
/// Název schématu databázové tabulky.
/// </summary>
public string DbSchema
{
get
{
CheckInitialization();
return dbSchema;
}
}
private string dbSchema;
/// <summary>
/// Název databázové tabulky.
/// </summary>
public string DbTable
{
get
{
CheckInitialization();
return dbTable;
}
}
private string dbTable;
/// <summary>
/// Název třídy dle databázové tabulky. Bez namespace.
/// </summary>
public string ClassName
{
get
{
CheckInitialization();
return className;
}
}
private string className;
/// <summary>
/// Namespace třídy dle databázové tabulky. Bez názvu samotné třídy.
/// </summary>
public string Namespace
{
get
{
CheckInitialization();
return namespaceName;
}
}
private string namespaceName;
/// <summary>
/// Property ve třídě.
/// </summary>
public PropertyInfoCollection Properties
{
get
{
CheckInitialization();
return properties;
}
}
private PropertyInfoCollection properties;
/// <summary>
/// Property, která označuje smazané záznamy.
/// </summary>
public FieldPropertyInfo DeletedProperty
{
get
{
CheckInitialization();
return deletedProperty;
}
}
private FieldPropertyInfo deletedProperty;
/// <summary>
/// Delegát metody (bez parametrů) vracující nový objekt.
/// </summary>
public CreateObjectDelegate CreateObjectMethod
{
get
{
CheckInitialization();
return createObjectMethod;
}
}
private CreateObjectDelegate createObjectMethod;
/// <summary>
/// Delegát metody vracující instanci objektu.
/// </summary>
public GetObjectDelegate GetObjectMethod
{
get
{
CheckInitialization();
return getObjectMethod;
}
}
private GetObjectDelegate getObjectMethod;
/// <summary>
/// Metoda vracející seznam všech instancí.
/// </summary>
public GetAllDelegate GetAllMethod
{
get
{
CheckInitialization();
return getAllMethod;
}
}
private GetAllDelegate getAllMethod;
/// <summary>
/// Nastaví instanci třídy.
/// </summary>
/// <param name="dbSchema">Název schémata databázové tabulky.</param>
/// <param name="dbTable">Název databázové tabulky.</param>
/// <param name="className">Název třídy.</param>
/// <param name="namespaceName">Název namespace třídy.</param>
/// <param name="readOnly">Určuje, zda je třída jen ke čtení.</param>
/// <param name="createObjectMethod">Delegát na metodu (bez parametrů) vytvářející instanci nového objektu. Null, pokud taková metoda neexistuje (třída je readonly nebo máowner field).</param>
/// <param name="getObjectMethod">Delegát na metodu vracející objekt třídy na základě ID.</param>
/// <param name="getAllMethod">Delegát na metodu vracející všechny (nesmazané) objekty třídy.</param>
/// <param name="deletedProperty">FieldPropertyInfo, která identifikuje příznakem smazané záznamy.</param>
/// <param name="properties">Kolekce všech vlastností objektu.</param>
[SuppressMessage("SonarLint", "S1117", Justification = "Není chybou mít parametr metody stejného jména ve třídě.")]
public void Initialize(
string dbSchema,
string dbTable,
string className,
string namespaceName,
bool readOnly,
CreateObjectDelegate createObjectMethod,
GetObjectDelegate getObjectMethod,
GetAllDelegate getAllMethod,
FieldPropertyInfo deletedProperty,
PropertyInfoCollection properties)
{
this.dbSchema = dbSchema;
this.dbTable = dbTable;
this.className = className;
this.namespaceName = namespaceName;
this.readOnly = readOnly;
this.createObjectMethod = createObjectMethod;
this.getObjectMethod = getObjectMethod;
this.getAllMethod = getAllMethod;
this.deletedProperty = deletedProperty;
this.properties = properties;
this.isInitialized = true;
}
private bool isInitialized = false;
/// <summary>
/// Ověří, že byla instance inicializována. Pokud ne, vyhodí výjimku.
/// </summary>
protected void CheckInitialization()
{
if (!isInitialized)
{
throw new InvalidOperationException("Instance nebyla inicializována.");
}
}
}