-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathAutoFixtureLibrary.pas
93 lines (85 loc) · 2.63 KB
/
AutoFixtureLibrary.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
unit AutoFixtureLibrary;
interface
uses
RTTI,
AutoFixtureSetup;
type
TAutofixtureLibrary = class
class procedure GetMethods(ASetup: TAutofixtureSetup; AType: TRttiType; var vConstructor: TRttiMethod; var vAddMethod: TRttiMethod);
end;
implementation
{ TAutofixtureLibrary }
class procedure TAutofixtureLibrary.GetMethods(ASetup: TAutofixtureSetup; AType: TRttiType; var vConstructor, vAddMethod: TRttiMethod);
var
vMethod: TRttiMethod;
begin
vConstructor := nil;
vAddMethod := nil;
if ASetup.ConstructorSearch = TConstructorSearch.csSimplest then begin
// Find simplest constructor deklareret i klassen
for vMethod in AType.GetMethods do begin
if vMethod.IsConstructor then begin
if Assigned(vConstructor) then begin
// don't shift to parent class constructor once class constructor found
if vMethod.Parent = AType then begin
if vConstructor.Parent = AType then begin
if Length(vMethod.GetParameters) < Length(vConstructor.GetParameters) then begin
vConstructor := vMethod;
end;
end
else begin
vConstructor := vMethod;
end;
end
else begin
if vConstructor.Parent <> AType then begin
if Length(vMethod.GetParameters) < Length(vConstructor.GetParameters) then begin
vConstructor := vMethod;
end;
end;
end;
end
else begin
vConstructor := vMethod;
end;
end
else if vMethod.Name = 'Add' then begin
if Assigned(vAddMethod) then begin
if (vMethod.Parent = AType) and (vAddMethod.Parent <> AType) then begin
vAddMethod := vMethod;
end;
end
else begin
vAddMethod := vMethod;
end;
end;
end;
end
else if ASetup.ConstructorSearch = TConstructorSearch.csMostParams then begin
// Find constructor with many params
for vMethod in AType.GetDeclaredMethods do begin
if vMethod.IsConstructor then begin
if Assigned(vConstructor) then begin
if Length(vMethod.GetParameters) > Length(vConstructor.GetParameters) then begin
vConstructor := vMethod;
end;
end
else begin
vConstructor := vMethod;
end;
end
else if vMethod.Name = 'Add' then begin
vAddMethod := vMethod;
end;
end;
end
else begin
// Find only add method
for vMethod in AType.GetDeclaredMethods do begin
if vMethod.Name = 'Add' then begin
vAddMethod := vMethod;
end;
end;
end;
end;
end.