-
Notifications
You must be signed in to change notification settings - Fork 27
/
Copy pathPkg.Json.Settings.pas
71 lines (56 loc) · 1.64 KB
/
Pkg.Json.Settings.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
unit Pkg.Json.Settings;
interface
uses
Pkg.Json.DTO;
Type
TSettings = class(TJsonDTO)
private
class var FInstance: TSettings;
var
FAddJsonPropertyAttributes: Boolean;
FPostFix: string;
FPostFixClassNames: Boolean;
FUsePascalCase: Boolean;
FSuppressZeroDate: Boolean;
constructor MakeSingleton;
public
constructor Create; reintroduce; deprecated 'Don''t use this!';
class function Instance: TSettings;
class function GetPostFix: string;
property AddJsonPropertyAttributes: Boolean read FAddJsonPropertyAttributes write FAddJsonPropertyAttributes;
property PostFixClassNames: Boolean read FPostFixClassNames write FPostFixClassNames;
property PostFix: string read FPostFix write FPostFix;
property UsePascalCase: Boolean read FUsePascalCase write FUsePascalCase;
property SuppressZeroDate: Boolean read FSuppressZeroDate write FSuppressZeroDate;
end;
implementation
uses
System.SysUtils, System.Strutils;
{ TSettings }
constructor TSettings.Create;
begin
raise Exception.Create('Don''t call the constructor directly!');
end;
class function TSettings.GetPostFix: string;
begin
Result := IfThen(Instance.PostFixClassNames, Instance.PostFix, string.empty);
end;
class function TSettings.Instance: TSettings;
begin
if not Assigned(FInstance) then
FInstance := TSettings.MakeSingleton;
Result := FInstance;
end;
constructor TSettings.MakeSingleton;
begin
inherited Create;
FUsePascalCase := True;
FAddJsonPropertyAttributes := False;
FPostFixClassNames := False;
FPostFix := 'DTO';
FSuppressZeroDate := True;
end;
initialization
finalization
TSettings.Instance.Free;
end.