CodePorting.Translator Cs2Cpp
CodePorting.Translator.Cs2Cpp.Framework
object_type.h
1
2#pragma once
3
4#include <system/object.h>
5#include <system/smart_ptr.h>
6#include <system/weak_ptr.h>
7#include <system/convert.h>
8#include <system/decimal.h>
9#include <system/nullable.h>
10#include <system/int32.h>
11#include <system/int64.h>
12#include <system/void.h>
13
14#include <initializer_list>
15#include <array>
16#include <utility>
17#include <type_traits>
18
19namespace System
20{
21
26{
27public:
33 template<typename T>
34 static inline typename std::enable_if<IsSmartPtr<T>::value, const System::TypeInfo&>::type GetType(const T& obj)
35 {
36 return obj->GetType();
37 }
38
44 template<typename T>
45 static inline typename std::enable_if<!IsExceptionWrapper<T>::value && !IsSmartPtr<T>::value && !std::is_fundamental<T>::value && !std::is_enum<T>::value && !IsNullable<T>::value, const System::TypeInfo&>::type GetType(const T& obj)
46 {
47 return obj.GetType();
48 }
49
55 template<typename T>
56 static inline typename std::enable_if<IsExceptionWrapper<T>::value, const System::TypeInfo&>::type GetType(const T& obj)
57 {
58 return obj.Get()->GetType();
59 }
60
66 template<typename T>
67 static inline typename std::enable_if<std::is_fundamental<T>::value || std::is_enum<T>::value, const System::TypeInfo&>::type GetType(const T obj)
68 {
69 return GetType<T>();
70 }
71
77 template<typename T>
78 static inline typename std::enable_if<IsNullable<T>::value, const System::TypeInfo&>::type GetType(const T obj)
79 {
80 if (!obj.get_HasValue())
81 {
82 // Getting type of empty nullable throws an exception
83 Details::ThrowNullableNullReference();
84 }
85
86 return GetType<typename T::ValueType>();
87 }
88
93 template <typename T>
94 static inline typename std::enable_if<std::is_fundamental<T>::value && !std::is_enum<T>::value, const System::TypeInfo&>::type GetType()
95 {
96 return TypeInfo::BoxedValueType<T>();
97 }
98
103 template <typename T>
104 static inline typename std::enable_if<std::is_enum<T>::value, const System::TypeInfo&>::type GetType()
105 {
106 return TypeInfo::BoxedValueType<T>();
107 }
108
113 template <typename T>
114 static inline typename std::enable_if<(!std::is_fundamental<T>::value && !std::is_enum<T>::value && !IsBoxable<T>::value) || IsExceptionWrapper<T>::value, const System::TypeInfo&>::type GetType()
115 {
116 return T::Type(); // Works for pointers as well - they redirect Type() call to Pointee_::Type()
117 }
118
123 template <typename T>
124 static inline typename std::enable_if<IsNullable<T>::value, const System::TypeInfo&>::type GetType()
125 {
126 return T::Type(); // Works for pointers as well - they redirect Type() call to Pointee_::Type()
127 }
128
133 template <typename T>
134 static inline typename std::enable_if<detail::is_a<T, MulticastDelegate>::value, const System::TypeInfo&>::type GetType()
135 {
136 return T::Type(); // Works for pointers as well - they redirect Type() call to Pointee_::Type()
137 }
138
143 template <typename T>
144 static inline typename std::enable_if<
145 !std::is_fundamental<T>::value &&
146 !std::is_enum<T>::value &&
150 const System::TypeInfo&>::type GetType()
151 {
152 return TypeInfo::BoxedValueType<T>(); // Works for pointers as well - they redirect Type() call to Pointee_::Type()
153 }
154
159 static inline const System::TypeInfo& GetType(const String& obj)
160 {
161 ASPOSE_UNUSED(obj);
162 return System::String::Type();
163 }
164};
165
168template <>
169inline const System::TypeInfo& ObjectType::GetType<uint8_t>()
170{
171 return System::Byte::Type();
172}
173
176template <>
177inline const System::TypeInfo& ObjectType::GetType<char16_t>()
178{
179 return System::Char::Type();
180}
181
184template <>
185inline const System::TypeInfo& ObjectType::GetType<int32_t>()
186{
187 return System::Int32::Type();
188}
189
192template <>
193inline const System::TypeInfo& ObjectType::GetType<int64_t>()
194{
195 return System::Int64::Type();
196}
197
200template <>
201inline const System::TypeInfo& ObjectType::GetType<bool>()
202{
203 return System::Boolean::Type();
204}
205
208template <>
209inline const System::TypeInfo& ObjectType::GetType<System::String>()
210{
211 return System::String::Type();
212}
213
216template <>
217inline const System::TypeInfo& ObjectType::GetType<System::DateTime>()
218{
219 return System::DateTime::Type();
220}
221
224template <>
225inline const System::TypeInfo& ObjectType::GetType<void>()
226{
227 return System::Void::Type();
228}
229
230} // namespace System
static const TypeInfo & Type()
Returns a TypeInfo object that contains information about this class.
Definition: date_time.h:654
Provides static methods that implement object type getters. This is a static type with no instance se...
Definition: object_type.h:26
static std::enable_if< std::is_enum< T >::value, constSystem::TypeInfo & >::type GetType()
Implements typeof() translation. Overload for enum types.
Definition: object_type.h:104
static std::enable_if< detail::is_a< T, MulticastDelegate >::value, constSystem::TypeInfo & >::type GetType()
Implements typeof() translation. Overload for MutlicastDelegate.
Definition: object_type.h:134
static std::enable_if< std::is_fundamental< T >::value||std::is_enum< T >::value, constSystem::TypeInfo & >::type GetType(const T obj)
Implements typeof() translation. Overload for primitive types.
Definition: object_type.h:67
static std::enable_if<!std::is_fundamental< T >::value &&!std::is_enum< T >::value &&IsBoxable< T >::value &&!detail::is_a< T, MulticastDelegate >::value &&!IsNullable< T >::value, constSystem::TypeInfo & >::type GetType()
Implements typeof() translation. Overload for structures and pointers.
Definition: object_type.h:150
static std::enable_if< IsNullable< T >::value, constSystem::TypeInfo & >::type GetType(const T obj)
Implements typeof() translation. Overload for Nullable types.
Definition: object_type.h:78
static const System::TypeInfo & GetType(const String &obj)
Implements typeof() translation. Overload for string type.
Definition: object_type.h:159
static std::enable_if< std::is_fundamental< T >::value &&!std::is_enum< T >::value, constSystem::TypeInfo & >::type GetType()
Implements typeof() translation. Overload for primitive types.
Definition: object_type.h:94
static std::enable_if<(!std::is_fundamental< T >::value &&!std::is_enum< T >::value &&!IsBoxable< T >::value)||IsExceptionWrapper< T >::value, constSystem::TypeInfo & >::type GetType()
Implements typeof() translation. Overload for structures and pointers.
Definition: object_type.h:114
static std::enable_if< IsNullable< T >::value, constSystem::TypeInfo & >::type GetType()
Implements typeof() translation. Overload for Nullable.
Definition: object_type.h:124
static std::enable_if<!IsExceptionWrapper< T >::value &&!IsSmartPtr< T >::value &&!std::is_fundamental< T >::value &&!std::is_enum< T >::value &&!IsNullable< T >::value, constSystem::TypeInfo & >::type GetType(const T &obj)
Implements typeof() translation. Overload for structures.
Definition: object_type.h:45
static std::enable_if< IsExceptionWrapper< T >::value, constSystem::TypeInfo & >::type GetType(const T &obj)
Implements typeof() translation. Overload for exceptions.
Definition: object_type.h:56
static std::enable_if< IsSmartPtr< T >::value, constSystem::TypeInfo & >::type GetType(const T &obj)
Implements typeof() translation. Overload for smart pointers.
Definition: object_type.h:34
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
Definition: db_command.h:9
Template predicate that checks if boxing of the specified type is supported.
Definition: boxable_traits.h:16
A template predicate that determines if the specified type is a Exception class or its descendant.
Definition: object.h:405
A template predicate that determines if its template argument T in Nullable or its subclass.
Definition: nullable.h:23
Trait class to check if a type is a specialization of SmartPtr class.
Definition: smart_ptr.h:1499
Tests if specific type is a specialization of specific template. If it is, inherits std::true_type,...
Definition: detail.h:80