CodePorting.Translator Cs2Cpp
CodePorting.Translator.Cs2Cpp.Framework
property_info.h
1
2#pragma once
3#include <functional>
4#include <system/object_ext.h>
5#include <system/delegate.h>
6#include <system/object.h>
7#include <system/string.h>
8#include <system/reflection/member_info.h>
9#include <system/collections/list.h>
10
11namespace System { namespace Reflection {
12
14class ASPOSECPP_SHARED_CLASS PropertyInfo : public MemberInfo
15{
16public:
35
38 ASPOSECPP_SHARED_API TypeInfo get_PropertyType();
39
41 ASPOSECPP_SHARED_API virtual MemberTypes get_MemberType() const override;
42
45 void set_PropertyType(const TypeInfo& type)
46 {
47 m_property_type = type;
48 }
49
55 template <class PropertyType, typename ClassType>
57 String name,
58 System::SharedPtr<PropertyType>(ClassType::*get_prop_method)() const) :
59 MemberInfo(name)
60 {
61 std::function<System::SharedPtr<PropertyType>(ClassType *)> get_function = get_prop_method;
62
63 set_method = [=](const System::Object::ptr& obj, const System::Object::ptr& value) -> void {
64 throw NotImplementedException();
65 };
66 get_method = [=](const System::Object::ptr& obj) -> System::Object::ptr {
67 return get_function((ClassType *)obj.get());
68 };
69
70 }
71
77 template <class PropertyType, typename ClassType>
79 String name,
80 System::SharedPtr<PropertyType>(ClassType::*get_prop_method)() ) :
81 MemberInfo(name)
82 {
83 std::function<System::SharedPtr<PropertyType>(ClassType *)> get_function = get_prop_method;
84
85 set_method = [=](const System::Object::ptr& obj, const System::Object::ptr& value) -> void {
86 throw NotImplementedException();
87 };
88 get_method = [=](const System::Object::ptr& obj) -> System::Object::ptr {
89 return get_function((ClassType *)obj.get());
90 };
91
92 }
93
100 template <class PropertyType, typename ClassType>
102 String name,
103 void (ClassType::*set_prop_method)(System::SharedPtr<PropertyType>),
104 System::SharedPtr<PropertyType> (ClassType::*get_prop_method)() const) :
105 MemberInfo(name)
106 {
107 std::function<void(ClassType *, System::SharedPtr<PropertyType>)> set_function = set_prop_method;
108 std::function<System::SharedPtr<PropertyType>(ClassType *)> get_function = get_prop_method;
109
110 set_method = [=](const System::Object::ptr& obj, System::Object::ptr value) -> void {
111 set_function((ClassType *)obj.get(), ExplicitCast<PropertyType>(value));
112 };
113 get_method = [=](const System::Object::ptr& obj) -> System::Object::ptr {
114 return get_function((ClassType *)obj.get());
115 };
116
117 }
118
125 template <class NullableType, typename ClassType>
127 String name,
128 void (ClassType::*set_prop_method)(System::Nullable<NullableType>),
129 System::Nullable<NullableType>(ClassType::*get_prop_method)()) :
130 MemberInfo(name)
131 {
132 std::function<void(ClassType *, System::Nullable<NullableType>)> set_function = set_prop_method;
133 std::function<System::Nullable<NullableType>(ClassType *)> get_function = get_prop_method;
134
135 set_method = [=](const System::Object::ptr& obj, System::Object::ptr value) -> void {
136 set_function((ClassType *)obj.get(), System::ObjectExt::UnboxToNullable<NullableType>(value));
137 };
138 get_method = [=](const System::Object::ptr& obj) -> System::Object::ptr {
139 System::Nullable<NullableType> value = get_function((ClassType *)obj.get());
140 return System::ObjectExt::Box<System::Nullable<NullableType>>(value);
141 };
142
143 }
144
151 template <class NullableType, typename ClassType>
153 String name,
154 void (ClassType::*set_prop_method)(System::Nullable<NullableType>),
155 System::Nullable<NullableType>(ClassType::*get_prop_method)() const) :
156 MemberInfo(name)
157 {
158 std::function<void(ClassType *, System::Nullable<NullableType>)> set_function = set_prop_method;
159 std::function<System::Nullable<NullableType>(ClassType *)> get_function = get_prop_method;
160
161 set_method = [=](const System::Object::ptr& obj, System::Object::ptr value) -> void {
162 set_function((ClassType *)obj.get(), System::ObjectExt::UnboxToNullable<NullableType>(value));
163 };
164 get_method = [=](const System::Object::ptr& obj) -> System::Object::ptr {
165 System::Nullable<NullableType> value = get_function((ClassType *)obj.get());
166 return System::ObjectExt::Box<System::Nullable<NullableType>>(value);
167 };
168
169 }
170
177 template <class PropertyType, typename ClassType>
179 String name,
180 void (ClassType::*set_prop_method)(System::SharedPtr<PropertyType>),
181 System::SharedPtr<PropertyType>(ClassType::*get_prop_method)()) :
182 MemberInfo(name)
183 {
184 std::function<void(ClassType *, System::SharedPtr<PropertyType>)> set_function = set_prop_method;
185 std::function<System::SharedPtr<PropertyType>(ClassType *)> get_function = get_prop_method;
186
187 set_method = [=](const System::Object::ptr& obj, System::Object::ptr value) -> void {
188 set_function(dynamic_cast<ClassType*>(obj.get()), ExplicitCast<PropertyType>(value));
189 };
190 get_method = [=](const System::Object::ptr& obj) -> System::Object::ptr {
191 return get_function(dynamic_cast<ClassType *>(obj.get()));
192 };
193
194 }
195
201 template <typename ClassType>
203 String name,
204 void (ClassType::*set_prop_method)(System::String),
205 System::String (ClassType::*get_prop_method)()) :
206 MemberInfo(name)
207 {
208 std::function<void(ClassType *, String)> set_function = set_prop_method;
209 std::function<String(ClassType *)> get_function = get_prop_method;
210
211 set_method = [=](const System::Object::ptr& obj, const System::Object::ptr& value) -> void {
212 set_function(dynamic_cast<ClassType *>(obj.get()), System::ObjectExt::Unbox<String>(value));
213 };
214 get_method = [=](const System::Object::ptr& obj) -> System::Object::ptr {
215 String value = get_function(dynamic_cast<ClassType *>(obj.get()));
216 return System::ObjectExt::Box<String>(value);
217 };
218 }
219
225 template <typename ClassType>
227 String name,
228 void (ClassType::*set_prop_method)(System::String),
229 System::String(ClassType::*get_prop_method)() const) :
230 MemberInfo(name)
231 {
232 std::function<void(ClassType *, String)> set_function = set_prop_method;
233 std::function<String(ClassType *)> get_function = get_prop_method;
234
235 set_method = [=](const System::Object::ptr& obj, const System::Object::ptr& value) -> void {
236 set_function(dynamic_cast<ClassType *>(obj.get()), System::ObjectExt::Unbox<String>(value));
237 };
238 get_method = [=](const System::Object::ptr& obj) -> System::Object::ptr {
239 String value = get_function(dynamic_cast<ClassType *>(obj.get()));
240 return System::ObjectExt::Box<String>(value);
241 };
242 }
243
249 template <typename ClassType>
251 String name,
252 void (ClassType::*set_prop_method)(System::Decimal),
253 System::Decimal (ClassType::*get_prop_method)()) :
254 MemberInfo(name)
255 {
256 std::function<void(ClassType *, Decimal)> set_function = set_prop_method;
257 std::function<Decimal(ClassType *)> get_function = get_prop_method;
258
259 set_method = [=](const System::Object::ptr& obj, const System::Object::ptr& value) -> void {
260 set_function(dynamic_cast<ClassType *>(obj.get()), System::ObjectExt::Unbox<Decimal>(value));
261 };
262 get_method = [=](const System::Object::ptr& obj) -> System::Object::ptr {
263 Decimal value = get_function(dynamic_cast<ClassType *>(obj.get()));
264 return System::ObjectExt::Box<Decimal>(value);
265 };
266 }
267
273 template <typename ClassType>
275 String name,
276 void (ClassType::*set_prop_method)(System::Decimal),
277 System::Decimal(ClassType::*get_prop_method)() const) :
278 MemberInfo(name)
279 {
280 std::function<void(ClassType *, Decimal)> set_function = set_prop_method;
281 std::function<Decimal(ClassType *)> get_function = get_prop_method;
282
283 set_method = [=](const System::Object::ptr& obj, const System::Object::ptr& value) -> void {
284 set_function(dynamic_cast<ClassType *>(obj.get()), System::ObjectExt::Unbox<Decimal>(value));
285 };
286 get_method = [=](const System::Object::ptr& obj) -> System::Object::ptr {
287 Decimal value = get_function(dynamic_cast<ClassType *>(obj.get()));
288 return System::ObjectExt::Box<Decimal>(value);
289 };
290 }
291
292
298 template <typename ClassType>
300 String name,
301 void (ClassType::*set_prop_method)(bool),
302 bool (ClassType::*get_prop_method)()) :
303 MemberInfo(name)
304 {
305 std::function<void(ClassType *, bool)> set_function = set_prop_method;
306 std::function<bool(ClassType *)> get_function = get_prop_method;
307
308 set_method = [=](const System::Object::ptr& obj, const System::Object::ptr& value) -> void {
309 set_function(dynamic_cast<ClassType *>(obj.get()), System::ObjectExt::Unbox<bool>(value));
310 };
311 get_method = [=](const System::Object::ptr& obj) -> System::Object::ptr {
312 bool value = get_function(dynamic_cast<ClassType *>(obj.get()));
313 return System::ObjectExt::Box<bool>(value);
314 };
315 }
316
322 template <typename ClassType>
324 String name,
325 void (ClassType::*set_prop_method)(bool),
326 bool (ClassType::*get_prop_method)() const) :
327 MemberInfo(name)
328 {
329 std::function<void(ClassType *, bool)> set_function = set_prop_method;
330 std::function<bool(ClassType *)> get_function = get_prop_method;
331
332 set_method = [=](const System::Object::ptr& obj, const System::Object::ptr& value) -> void {
333 set_function(dynamic_cast<ClassType *>(obj.get()), System::ObjectExt::Unbox<bool>(value));
334 };
335 get_method = [=](const System::Object::ptr& obj) -> System::Object::ptr {
336 bool value = get_function(dynamic_cast<ClassType *>(obj.get()));
337 return System::ObjectExt::Box<bool>(value);
338 };
339 }
340
346 template <typename ClassType>
348 String name,
349 void (ClassType::*set_prop_method)(int64_t),
350 int64_t (ClassType::*get_prop_method)()) :
351 MemberInfo(name)
352 {
353 std::function<void(ClassType *, int64_t)> set_function = set_prop_method;
354 std::function<int64_t(ClassType *)> get_function = get_prop_method;
355
356 set_method = [=](const System::Object::ptr& obj, const System::Object::ptr& value) -> void {
357 set_function(dynamic_cast<ClassType *>(obj.get()), System::ObjectExt::Unbox<int64_t>(value));
358 };
359 get_method = [=](const System::Object::ptr& obj) -> System::Object::ptr {
360 int64_t value = get_function(dynamic_cast<ClassType *>(obj.get()));
361 return System::ObjectExt::Box<int64_t>(value);
362 };
363 }
364
370 template <typename ClassType>
372 String name,
373 void (ClassType::*set_prop_method)(int64_t),
374 int64_t (ClassType::*get_prop_method)() const) :
375 MemberInfo(name)
376 {
377 std::function<void(ClassType *, int64_t)> set_function = set_prop_method;
378 std::function<int64_t(ClassType *)> get_function = get_prop_method;
379
380 set_method = [=](const System::Object::ptr& obj, const System::Object::ptr& value) -> void {
381 set_function(dynamic_cast<ClassType *>(obj.get()), System::ObjectExt::Unbox<int64_t>(value));
382 };
383 get_method = [=](const System::Object::ptr& obj) -> System::Object::ptr {
384 int64_t value = get_function(dynamic_cast<ClassType *>(obj.get()));
385 return System::ObjectExt::Box<int64_t>(value);
386 };
387 }
388
389protected:
393};
394
395}}
Represents a decimal number. This type should be allocated on stack and passed to functions by value ...
Definition: decimal.h:107
Forward declaration.
Definition: nullable.h:74
SmartPtr< Object > ptr
Alias for smart pointer type.
Definition: object.h:65
Provides reflection information on members. Objects of this class should only be allocated using Syst...
Definition: member_info.h:16
Represents property information.
Definition: property_info.h:15
void set_PropertyType(const TypeInfo &type)
Sets the type of this property.
Definition: property_info.h:45
PropertyInfo(String name, void(ClassType::*set_prop_method)(System::Nullable< NullableType >), System::Nullable< NullableType >(ClassType::*get_prop_method)())
Constructor. Nullable property with setter and getter.
Definition: property_info.h:126
PropertyInfo(String name, void(ClassType::*set_prop_method)(System::Nullable< NullableType >), System::Nullable< NullableType >(ClassType::*get_prop_method)() const)
Constructor. Nullable property with const getter only.
Definition: property_info.h:152
PropertyInfo(String name, void(ClassType::*set_prop_method)(System::String), System::String(ClassType::*get_prop_method)() const)
Constructs string property information from class with const getter.
Definition: property_info.h:226
PropertyInfo(String name, System::SharedPtr< PropertyType >(ClassType::*get_prop_method)())
Constructor. Property with only non-const getter.
Definition: property_info.h:78
PropertyInfo(String name, void(ClassType::*set_prop_method)(int64_t), int64_t(ClassType::*get_prop_method)() const)
Constructs int64_t property information from class with const getter.
Definition: property_info.h:371
TypeInfo m_property_type
Definition: property_info.h:392
PropertyInfo(String name, void(ClassType::*set_prop_method)(bool), bool(ClassType::*get_prop_method)())
Constructs boolean property information.
Definition: property_info.h:299
std::function< void(System::Object::ptr, System::Object::ptr)> set_method
Definition: property_info.h:390
PropertyInfo(String name, void(ClassType::*set_prop_method)(System::Decimal), System::Decimal(ClassType::*get_prop_method)())
Constructs Decimal property information.
Definition: property_info.h:250
System::SharedPtr< System::Object > GetValue(System::SharedPtr< System::Object > obj)
Gets property value from specific object.
std::function< System::Object::ptr(System::Object::ptr)> get_method
Definition: property_info.h:391
virtual MemberTypes get_MemberType() const override
Gets a MemberTypes value indicating that this member is a property.
PropertyInfo(String name, void(ClassType::*set_prop_method)(int64_t), int64_t(ClassType::*get_prop_method)())
Constructs int64_t property information.
Definition: property_info.h:347
TypeInfo get_PropertyType()
Gets property type.
PropertyInfo(String name, void(ClassType::*set_prop_method)(System::SharedPtr< PropertyType >), System::SharedPtr< PropertyType >(ClassType::*get_prop_method)() const)
Constructor.
Definition: property_info.h:101
PropertyInfo(String name, System::SharedPtr< PropertyType >(ClassType::*get_prop_method)() const)
Constructor. Property with only const getter.
Definition: property_info.h:56
PropertyInfo(String name, void(ClassType::*set_prop_method)(System::Decimal), System::Decimal(ClassType::*get_prop_method)() const)
Constructs Decimal property information from class with const getter.
Definition: property_info.h:274
void SetValue(System::SharedPtr< System::Object > obj, System::SharedPtr< System::Object > value, System::ArrayPtr< System::SharedPtr< System::Object > > indexer)
Sets property value to specific object.
void SetValue(System::SharedPtr< System::Object > obj, System::SharedPtr< System::Object > value)
Sets property value to specific object.
PropertyInfo(String name, void(ClassType::*set_prop_method)(System::SharedPtr< PropertyType >), System::SharedPtr< PropertyType >(ClassType::*get_prop_method)())
Constructor. Object property with getter only.
Definition: property_info.h:178
PropertyInfo(String name, void(ClassType::*set_prop_method)(bool), bool(ClassType::*get_prop_method)() const)
Constructs boolean property information from class with const getter.
Definition: property_info.h:323
PropertyInfo(String name, void(ClassType::*set_prop_method)(System::String), System::String(ClassType::*get_prop_method)())
Constructs string property information.
Definition: property_info.h:202
System::SharedPtr< System::Object > GetValue(System::SharedPtr< System::Object > obj, System::ArrayPtr< System::SharedPtr< System::Object > > indexer)
Gets property value from specific object.
Pointer class to wrap types being allocated on heap. Use it to manage memory for classes inheriting O...
Definition: smart_ptr.h:180
Pointee_ * get() const
Gets pointed object.
Definition: smart_ptr.h:518
String class used across the library. Is a substitute for C# System.String when translating code....
Definition: string.h:122
Represents a particular type and provides information about it.
Definition: type_info.h:109
MemberTypes
Marks each type of member.
Definition: member_types.h:11
Definition: db_command.h:9