从某一点来说,我厌倦了编写设置条件(and,or),因为对于更多条件或更长的变量名称,它开始变得笨拙并且令人讨厌再次写入.所以我开始写助手,所以我可以写ASet.ContainsOne([ceValue1, ceValue2])而不是(ceValue1 in ASet) or (ceValue2 in ASet).
type
TCustomEnum = (ceValue1, ceValue2, ceValue3);
TCustomSet = set of TCustomEnum;
TCustomSetHelper = record helper for TCustomSet
function ContainsOne(ASet: TCustomSet): Boolean;
function ContainsAll(ASet: TCustomSet): Boolean;
end;
implementation
function TCustomSetHelper.ContainsOne(ASet: TCustomSet): Boolean;
var
lValue : TCustomEnum;
begin
for lValue in ASet do
begin
if lValue in Self then
Exit(True);
end;
Result := False;
end;
function TCustomSetHelper.ContainsAll(ASet: TCustomSet): Boolean;
var
lValue : TCustomEnum;
begin
Result := …Run Code Online (Sandbox Code Playgroud)