Spring4d: Spring.Collections.IEnumerator and System.IEnumerator

I have a problem that should be trivial, but I cannot find an elegant answer.

I have an instance IList<string>, and I want to get a string, separated by commas, of all its distinct (case-insensitive) values.

I thought I was just using an assistant string.Joinfor this, since it has a good overload that accepts the IEnumerator<string>as parameter . Unfortunately, I see that I am trapped: spring4d overrides IEnumerator<T>and, of course, uses its own type everywhere.

As a result, the following code does not compile:

var
  distinct: system.IEnumerator<string>;
begin
  result := inherited GetToken;
  if assigned(result) then
  begin
    if not Modules.Contains(STR_DID_SESSION_MODULE) then
      Modules.Add(STR_DID_SESSION_MODULE); 
    distinct := TDistinctIterator<string>.Create(Modules, TIStringComparer.Ordinal);
    result.CustomClaims.Items[STR_CLAIM_CUSTOM_MODULES] := string.Join(',', distinct);
  end;
end;

Assignment distinctfails withE2010 Incompatible types: 'System.IEnumerator<System.string>' and 'Spring.Collections.Extensions.TDistinctIterator<System.string>'

Alternatively, if I remove the namespace from different, it causes a call string.Join.

, ? ?

+4
1

(FWIW , , TStringHelper.Join):

function StringJoin(const separator: string; const values: Spring.Collections.IEnumerable<string>): string; overload;
var
  e: Spring.Collections.IEnumerator<string>;
begin
  e := values.GetEnumerator;
  if not e.MoveNext then
    Exit('');
  Result := e.Current;
  while e.MoveNext do
    Result := Result + separator + e.Current;
end;

( Spring.Collections.Extensions):

StringJoin(',', TEnumerable.Distinct<string>(Modules, TStringComparer.OrdinalIgnoreCase))

, , IEnumerable<string> ToDelimitedString - .

+5

Source: https://habr.com/ru/post/1689895/


All Articles