Files
MycLib/Src/Data/Myc.Data.Types.Method.pas
T
Michael Schimmel d2f7b01911 Type System
2025-08-26 12:06:47 +02:00

133 lines
3.0 KiB
ObjectPascal

unit Myc.Data.Types.Method;
interface
uses
System.SysUtils,
System.Rtti,
Myc.Data.Types;
type
// Implements the IDataMethodType interface.
TImplDataMethodType = class(TInterfacedObject, IDataMethodType)
private
FArgType: IDataType;
FResultType: IDataType;
function GetName: String;
function GetKind: TDataKind;
function GetArgType: IDataType;
function GetResultType: IDataType;
function CreateValue(const AValue: TDataMethodProc): IDataMethodValue;
public
constructor Create(const AArgType, AResultType: IDataType);
end;
implementation
uses
System.Classes;
type
// Implements the IDataMethodValue interface.
TImplDataMethodValue = class(TInterfacedObject, IDataMethodValue)
private
FDataType: IDataMethodType;
FValue: TDataMethodProc;
function GetDataType: IDataType;
function GetAsString: string;
function AsTValue: TValue;
function GetValue: TDataMethodProc;
public
constructor Create(const ADataType: IDataMethodType; const AValue: TDataMethodProc);
end;
{ TImplDataMethodType }
constructor TImplDataMethodType.Create(const AArgType, AResultType: IDataType);
begin
inherited Create;
FArgType := AArgType;
FResultType := AResultType;
end;
function TImplDataMethodType.CreateValue(const AValue: TDataMethodProc): IDataMethodValue;
begin
Assert(Assigned(AValue));
Result := TImplDataMethodValue.Create(Self, AValue);
end;
function TImplDataMethodType.GetArgType: IDataType;
begin
Result := FArgType;
end;
function TImplDataMethodType.GetResultType: IDataType;
begin
Result := FResultType;
end;
function TImplDataMethodType.GetKind: TDataKind;
begin
Result := dkMethod;
end;
function TImplDataMethodType.GetName: String;
var
sb: TStringBuilder;
argName, resultName: string;
begin
if Assigned(FArgType) then
argName := FArgType.Name
else
argName := 'Void';
if Assigned(FResultType) then
resultName := FResultType.Name
else
resultName := 'Void';
sb := TStringBuilder.Create;
try
sb.Append('Method<');
sb.Append(argName);
sb.Append(' -> ');
sb.Append(resultName);
sb.Append('>');
Result := sb.ToString;
finally
sb.Free;
end;
end;
{ TImplDataMethodValue }
constructor TImplDataMethodValue.Create(const ADataType: IDataMethodType; const AValue: TDataMethodProc);
begin
inherited Create;
FDataType := ADataType;
FValue := AValue;
end;
function TImplDataMethodValue.GetDataType: IDataType;
begin
Result := FDataType;
end;
function TImplDataMethodValue.GetAsString: string;
begin
Result := '<METHOD>';
end;
function TImplDataMethodValue.AsTValue: TValue;
begin
Result := TValue.From<TDataMethodProc>(FValue);
end;
function TImplDataMethodValue.GetValue: TDataMethodProc;
begin
Result := FValue;
end;
end.