-
-
Notifications
You must be signed in to change notification settings - Fork 36
/
CloudAPI.Converter.BasicTypes.pas
102 lines (88 loc) · 2.84 KB
/
CloudAPI.Converter.BasicTypes.pas
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
unit CloudAPI.Converter.BasicTypes;
interface
uses
CloudAPI.RequestArgument;
type
TcaBasicConverters = class
private
class procedure StringConverter(AConverterManager: TcaRequestArgument);
class procedure IntegerConverter(AConverterManager: TcaRequestArgument);
class procedure Int64Converter(AConverterManager: TcaRequestArgument);
class procedure SingleConverter(AConverterManager: TcaRequestArgument);
class procedure BooleanConverter(AConverterManager: TcaRequestArgument);
class procedure TDateTimeConverter(AConverterManager: TcaRequestArgument);
public
class procedure BasicConverter(AConverterManager: TcaRequestArgument);
end;
implementation
uses
System.DateUtils,
System.JSON.Serializers,
System.SysUtils,
System.Rtti;
{ TcaBasicConverters }
class procedure TcaBasicConverters.BasicConverter(AConverterManager: TcaRequestArgument);
begin
StringConverter(AConverterManager);
AConverterManager.RegisterToJson<TArray<string>>;
IntegerConverter(AConverterManager);
Int64Converter(AConverterManager);
BooleanConverter(AConverterManager);
SingleConverter(AConverterManager);
TDateTimeConverter(AConverterManager);
end;
class procedure TcaBasicConverters.BooleanConverter(AConverterManager: TcaRequestArgument);
begin
AConverterManager.RegisterConverter<Boolean>(
function(AValue: TValue): string
begin
Result := AValue.AsBoolean.ToString(TUseBoolStrs.True);
end);
end;
class procedure TcaBasicConverters.Int64Converter(AConverterManager: TcaRequestArgument);
begin
AConverterManager.RegisterConverter<Int64>(
function(AValue: TValue): string
begin
Result := AValue.AsInt64.ToString;
end);
end;
class procedure TcaBasicConverters.IntegerConverter(AConverterManager: TcaRequestArgument);
begin
AConverterManager.RegisterConverter<Integer>(
function(AValue: TValue): string
begin
Result := AValue.AsInteger.ToString;
end);
end;
class procedure TcaBasicConverters.SingleConverter(AConverterManager: TcaRequestArgument);
begin
AConverterManager.RegisterConverter<Single>(
function(AValue: TValue): string
var
FS: TFormatSettings;
begin
FS := TFormatSettings.Invariant;
Result := AValue.AsExtended.ToString(TFloatFormat.ffGeneral, 8, 6, FS);
end);
end;
class procedure TcaBasicConverters.StringConverter(AConverterManager: TcaRequestArgument);
begin
AConverterManager.RegisterConverter<string>(
function(AValue: TValue): string
begin
Result := AValue.AsString;
end);
end;
class procedure TcaBasicConverters.TDateTimeConverter(AConverterManager: TcaRequestArgument);
begin
AConverterManager.RegisterConverter<TDateTime>(
function(AValue: TValue): string
var
LValue: TDateTime;
begin
LValue := AValue.AsType<TDateTime>;
Result := DateTimeToUnix(LValue).ToString;
end);
end;
end.